Skip to content

wslservice: Add experimental.swiotlb .wslconfig setting#40518

Draft
asherkariv wants to merge 8 commits into
masterfrom
user/askariv/swiotlb-enable
Draft

wslservice: Add experimental.swiotlb .wslconfig setting#40518
asherkariv wants to merge 8 commits into
masterfrom
user/askariv/swiotlb-enable

Conversation

@asherkariv
Copy link
Copy Markdown

@asherkariv asherkariv commented May 13, 2026

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,K|M" (range mode): explicit bounce buffer location Example: experimental.swiotlb=0x100000000,64M

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
  • Appends "hv_pci_swiotlb=," to the kernel command line so the guest driver can locate the bounce buffer
  • Append ";swiotlb=" 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 fields, parsing, validation, virtiofs dependency check
  • WslCoreVm.cpp: kernel cmdline and virtiofs share name plumbing
  • Resources.resw: error/warning message strings

Related work items: https://microsoft.visualstudio.com/OS/_workitems/edit/61002501

Summary of the Pull Request

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

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
Copilot AI review requested due to automatic review settings May 13, 2026 01:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.swiotlb parsing/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.

Comment thread src/windows/common/WslCoreConfig.cpp Outdated
Comment thread src/windows/common/WslCoreConfig.cpp Outdated
Comment thread src/shared/inc/lxinitshared.h Outdated
Comment thread src/windows/common/WslCoreConfig.cpp
Comment thread src/windows/service/inc/wslservice.idl Outdated
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
Copilot AI review requested due to automatic review settings May 13, 2026 21:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread src/windows/common/WslCoreConfig.h Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread test/windows/UnitTests.cpp Outdated
@benhillis
Copy link
Copy Markdown
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants