wslservice: Add experimental.swiotlb .wslconfig setting#40518
Draft
asherkariv wants to merge 8 commits into
Draft
wslservice: Add experimental.swiotlb .wslconfig setting#40518asherkariv wants to merge 8 commits into
asherkariv wants to merge 8 commits into
Conversation
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:
- "0x<gpa>,<size>m|k" (range mode): explicit bounce buffer location
Example: experimental.swiotlb=0x100000000,64M
- "lowmem" (lowmem mode): heuristic sub-4GB allocation
Behavior:
- Validated against regex at config parse time; invalid values emit
a user warning and are ignored
- Requires virtiofs to be enabled; emits a warning and clears the
setting if virtiofs is disabled
- Range mode appends "hv_pci_swiotlb=<gpa>,<size>" to the kernel
command line so the guest driver can locate the bounce buffer
- Both modes append ";swiotlb=<value>" to the virtiofs mount options
string, which wsldevicehost.dll parses as a control configuration
token and strips before passing mount options to the guest
Files changed:
- WslCoreConfig.h/cpp: SwiotlbCfg/SwiotlbKernelCfg fields, parsing,
validation, virtiofs dependency check
- WslCoreVm.cpp: kernel cmdline and virtiofs share name plumbing
- wslservice.idl: LXSS_VM_KERNEL_SWIOTLB_CONFIG constant
- lxinitshared.h: LX_INIT_SWIOTLB_MOUNT_OPTIONS constant
- Resources.resw: error/warning message strings
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
PR comments: experimental.swiotlb plumbing change.
Behavior:
* Default SwiotlbCfg to "lowmem" so virtiofs gets a SWIOTLB region
even when the user does not set experimental.swiotlb explicitly.
* Clear SwiotlbCfg/SwiotlbKernelCfg at the top of parseSwiotlb so
a malformed value does not silently fall back to the previous
(now non-empty) default; instead the feature is disabled and the
"Invalid SWIOTLB value ..." warning is emitted.
Cleanup:
* Inline the ";swiotlb=" mount-option token at its single use site
in WslCoreVm::AddDrvFsShare and drop the LX_INIT_SWIOTLB_MOUNT_OPTIONS
macro from src/shared/inc/lxinitshared.h (the macro was only
referenced once and is not needed by Linux-side code).
Tests:
* Add experimental.swiotlb cases to WSL2_TEST_METHOD(Warnings) in
test/windows/UnitTests.cpp, covering:
- valid gpa,size value with virtiofs disabled (default)
-> "requires virtiofs" warning
- valid "lowmem" with virtiofs disabled
-> "requires virtiofs" warning
- malformed value ("garbage") and unsupported size suffix
("0x100000000,64g") -> "Invalid SWIOTLB value ..." warning
- valid gpa,size value and "lowmem" with virtiofs enabled
(DrvFsMode::VirtioFs prefix) -> no warnings
Member
|
I might be confused but I thought we didn’t need this setting until we have the updated kernel? |
- Tighten regex to gpa,size only and add c_swiotlbDefault constant. - Remove SwiotlbKernelCfg field, LXSS_VM_KERNEL_SWIOTLB_CONFIG, and the separate kernel-pattern match; SwiotlbCfg now drives both consumers. - Only emit swiotlb=force / hv_pci_swiotlb= when SwiotlbCfg is set. - Update warning string and tests to match.
A user-supplied kernel may not accept hv_pci_swiotlb=, so clear SwiotlbCfg and emit MessageSwiotlbIncompatibleWithCustomKernel when wsl2.kernel is non-empty. Refactor Initialize to use the EMIT_USER_WARNING + VALIDATE_CONFIG_OPTION pattern (matching EnableVirtio9p) for both the kernel and virtio-consumer prerequisites; the default region is then applied only on the positive path.lease enter the commit message for your changes. Lines starting
Custom kernels are built on the WSL kernel base, which carries the required swiotlb patch, so the gate is unnecessary. Removes the KernelPath check and the MessageSwiotlbIncompatibleWithCustomKernel resource string. The EMIT_USER_WARNING + VALIDATE_CONFIG_OPTION style introduced alongside the gate is kept.
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