wslservice: Add experimental.swiotlb .wslconfig setting#40518
Draft
asherkariv wants to merge 2 commits into
Draft
wslservice: Add experimental.swiotlb .wslconfig setting#40518asherkariv wants to merge 2 commits into
asherkariv wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new experimental .wslconfig key (experimental.swiotlb) to control SWIOTLB bounce buffer behavior for WSL VMs using virtio devices. The setting is validated during config parsing, optionally propagated to the guest kernel command line (range mode), and also forwarded to wsldevicehost.dll via a virtiofs “name-with-options” control token.
Changes:
- Add
experimental.swiotlbparsing/validation and store both a virtiofs token value (SwiotlbCfg) and an optional kernel cmdline value (SwiotlbKernelCfg). - Plumb SWIOTLB configuration into virtiofs share options and (range mode) append
hv_pci_swiotlb=to the guest kernel command line. - Add new constants and localization strings for invalid-value and virtiofs-required warnings.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/windows/service/inc/wslservice.idl | Adds LXSS_VM_KERNEL_SWIOTLB_CONFIG constant used when building the kernel cmdline. |
| src/windows/service/exe/WslCoreVm.cpp | Appends SWIOTLB kernel parameter (range mode) and adds virtiofs control token in share options. |
| src/windows/common/WslCoreConfig.h | Adds config key name and new config fields (SwiotlbCfg, SwiotlbKernelCfg) + telemetry presence bit. |
| src/windows/common/WslCoreConfig.cpp | Implements experimental.swiotlb parsing/validation and enforces virtiofs dependency. |
| src/shared/inc/lxinitshared.h | Adds LX_INIT_SWIOTLB_MOUNT_OPTIONS mount-option/control-token prefix. |
| localization/strings/en-US/Resources.resw | Adds localized warning strings for invalid SWIOTLB and virtiofs-required cases. |
benhillis
reviewed
May 13, 2026
benhillis
reviewed
May 13, 2026
benhillis
reviewed
May 13, 2026
Member
|
I might be confused but I thought we didn’t need this setting until we have the updated kernel? |
benhillis
pushed a commit
that referenced
this pull request
May 18, 2026
…n WSLC A user-supplied WSL2 kernel without the WSL swiotlb patch ignores hv_pci_swiotlb= but still receives the wsldevicehost `;swiotlb=` tokens from PR #40518, mis-configuring DMA. Detect kernel support at runtime in mini_init via env-var presence (unrecognized key=value cmdline params are passed to init as env vars; early_param/__setup consumes them when the patch is present). Report the bit back through LX_INIT_GUEST_CAPABILITIES and cache the effective swiotlb value on WslCoreVm right after ReadGuestCapabilities so both consumer sites (drvfs virtiofs and VirtioProxy networking) reuse it and the kernel-unsupported warning fires at most once. Move drvfs thread spawn after ReadGuestCapabilities so the flag is available without a wait/event dance. Enable swiotlb unconditionally on WSLC since it ships its own patched kernel. Hoist c_swiotlbDefault to GuestDeviceManager.h and fold the swiotlb=force hv_pci_swiotlb=<cfg> append into AppendCommonKernelCommandLine. Replace the ad-hoc EnableVirtioFs/VirtioProxy consumer detection with the EnableVirtio master switch, which also covers WSLg's virtio-fs device. Reject NetworkingMode=VirtioProxy when EnableVirtio=false with a fallback to NAT and a user warning. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment on lines
+870
to
+884
| @@ -859,7 +881,7 @@ void WslCoreVm::AddDrvFsShare(_In_ bool Admin, _In_ HANDLE UserToken) | |||
| ULONG index; | |||
| WI_VERIFY(_BitScanForward(&index, fixedDrives) != FALSE); | |||
| const wchar_t fixedDrivePath[] = {gsl::narrow_cast<wchar_t>(L'A' + index), L':', L'\\', L'\0'}; | |||
| AddVirtioFsShare(Admin, fixedDrivePath, TEXT(LX_INIT_DEFAULT_PLAN9_MOUNT_OPTIONS), UserToken); | |||
| AddVirtioFsShare(Admin, fixedDrivePath, mountOptions.c_str(), UserToken); | |||
643d5f7 to
31ef8c1
Compare
Lets WSL2 users opt in to a swiotlb bounce buffer for virtio devices via .wslconfig. The setting is gated on a runtime kernel capability probe: mini_init checks whether hv_pci_swiotlb= was consumed by the kernel and reports the result back to wslservice through the guest capabilities channel. If the user enables swiotlb but the running kernel lacks the patch, the value is silently dropped and a one-time perf-hint warning is emitted. The configured value is appended as a ;swiotlb=<config> token to all virtio device option strings: initial fixed-drive virtiofs shares, dynamic virtiofs shares (guest add and remount paths), and the VirtioProxy virtio-net adapter (host-routed + loopback). WSLC ships its own patched kernel, so swiotlb is hardcoded on for WSLC virtio devices with no config knob. Also gates virtio-related settings behind a single EnableVirtio master switch and falls VirtioProxy networking back to NAT (or None) with a warning when the user disables virtio. Co-authored-by: Asher Kariv <askariv@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
31ef8c1 to
0468b35
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.
Add a new experimental .wslconfig key "experimental.swiotlb" that configures SWIOTLB bounce buffer parameters for WSL VMs using virtio devices. The setting is validated, propagated to wsldevicehost.dll via control tokens in the share name, and (for range mode) also passed to the guest kernel command line.
Supported values:
Behavior:
Files changed:
Related work items: https://microsoft.visualstudio.com/OS/_workitems/edit/61002501
Summary of the Pull Request
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed