415
addShare(TEXT(LXSS_GPU_PACKAGED_LIB_SHARE), path.c_str());
416
}
417
418
+ // Accept a connection from mini_init with a receive timeout so the service does not get stuck waiting for a response from the VM.
419
+ m_miniInitChannel =
420
+ wsl::shared::SocketChannel{AcceptConnection(m_vmConfig.KernelBootTimeout), "mini_init", {m_terminatingEvent.get()}};
421
+
422
+ // Accept the connection from the Linux guest for notifications.
423
+ m_notifyChannel = AcceptConnection(m_vmConfig.KernelBootTimeout);
424
+
425
+ // Receive and parse the guest kernel version
426
+ ReadGuestCapabilities();
427
+
428
+ // Cache the effective swiotlb configuration. The kernel picks a valid GPA, allocates the pool,
429
+ // and publishes the actual (base, size) via sysfs. Only warn when swiotlb was actually
430
+ // requested via the kernel command line; otherwise the kernel correctly doesn't allocate.
431
+ if (m_hvPciSwiotlbBase != 0 && m_hvPciSwiotlbSize != 0)
432
+ {
433
+ m_swiotlbOption = std::format(L"swiotlb=0x{:x},{}", m_hvPciSwiotlbBase, m_hvPciSwiotlbSize);
434
+ }
435
+ else if (m_vmConfig.SwiotlbSizeBytes != 0)
436
+ {
437
+ EMIT_USER_WARNING(wsl::shared::Localization::MessageSwiotlbKernelUnsupported());
438
+ }
439
+
440
// Asynchronously add drvfs devices if supported.
441
if (m_vmConfig.EnableHostFileSystemAccess)
442
{
460
}).detach();
461
}
462
441
- // Accept a connection from mini_init with a receive timeout so the service does not get stuck waiting for a response from the VM.
442
- m_miniInitChannel =
443
- wsl::shared::SocketChannel{AcceptConnection(m_vmConfig.KernelBootTimeout), "mini_init", {m_terminatingEvent.get()}};
444
-
445
- // Accept the connection from the Linux guest for notifications.
446
- m_notifyChannel = AcceptConnection(m_vmConfig.KernelBootTimeout);
447
-
448
- // Receive and parse the guest kernel version
449
- ReadGuestCapabilities();
450
-
463
// Mount the system distro.
464
// N.B. If using SCSI, the system distro is added during VM creation.
465
switch (m_systemDistroDeviceType)
598
WI_SetFlagIf(flags, wsl::core::VirtioNetworkingFlags::DnsTunneling, m_vmConfig.EnableDnsTunneling);
599
// NAT may have fallen back to virtio proxy after the early-config message; drop the unused DNS hvsocket.
600
dnsTunnelingSocket.reset();
601
+
602
m_networkingEngine = std::make_unique<wsl::core::VirtioNetworking>(
590
- std::move(gnsChannel), flags, LX_INIT_RESOLVCONF_FULL_HEADER, m_guestDeviceManager, m_userToken);
603
+ std::move(gnsChannel), flags, LX_INIT_RESOLVCONF_FULL_HEADER, m_guestDeviceManager, m_userToken, m_swiotlbOption);
604
}
605
else if (m_vmConfig.NetworkingMode == NetworkingMode::Bridged)
606
{
1552
kernelCmdLine += std::format(L" nr_cpus={}", m_vmConfig.ProcessorCount);
1553
1554
// Append common kernel parameters shared between WSL2 and WSLC.
1542
- helpers::AppendCommonKernelCommandLine(kernelCmdLine, m_pageReportingOrder);
1543
-
1544
- // If using virtio features, enable SWIOTLB as a perf optimization (will cause VM to consume 64MB more memory).
1545
- if (m_vmConfig.EnableVirtio9p || m_vmConfig.EnableVirtioFs || m_vmConfig.NetworkingMode == NetworkingMode::VirtioProxy)
1546
- {
1547
- kernelCmdLine += L" swiotlb=force";
1548
- }
1555
+ helpers::AppendCommonKernelCommandLine(kernelCmdLine, m_pageReportingOrder, m_vmConfig.SwiotlbSizeBytes);
1556
1557
if (m_vmConfig.EnableVirtio && helpers::IsVirtioSerialConsoleSupported())
1558
{
2169
2170
sharePath = std::filesystem::weakly_canonical(sharePath).wstring();
2171
2172
+ // Append the swiotlb token here so it covers fixed-drive, dynamic add, and remount paths.
2173
+ // Duplicate swiotlb tokens are harmless: VirtioFsShare parses options into a map.
2174
+ std::wstring effectiveOptions(Options);
2175
+ if (!m_swiotlbOption.empty())
2176
+ {
2177
+ if (!effectiveOptions.empty())
2178
+ {
2179
+ effectiveOptions += L';';
2180
+ }
2181
+
2182
+ effectiveOptions += m_swiotlbOption;
2183
+ }
2184
+
2185
// Check if a matching share already exists.
2186
bool created = false;
2187
std::wstring tag;
2168
- VirtioFsShare key(sharePath.c_str(), Options, Admin);
2188
+ VirtioFsShare key(sharePath.c_str(), effectiveOptions.c_str(), Admin);
2189
if (!m_virtioFsShares.contains(key))
2190
{
2191
// Generate a new unique tag for the share.
2218
"WslCoreVmAddVirtioFsShare",
2219
TraceLoggingValue(Admin, "admin"),
2220
TraceLoggingValue(sharePath.c_str(), "path"),
2201
- TraceLoggingValue(Options, "options"),
2221
+ TraceLoggingValue(effectiveOptions.c_str(), "options"),
2222
TraceLoggingValue(tag.c_str(), "tag"),
2223
TraceLoggingValue(created, "created"),
2224
TraceLoggingValue(m_virtioFsShares.size(), "shareCount"));
2329
}
2330
2331
m_seccompAvailable = info.SeccompAvailable;
2332
+ m_hvPciSwiotlbBase = info.HvPciSwiotlbBase;
2333
+ m_hvPciSwiotlbSize = info.HvPciSwiotlbSize;
2334
WSL_LOG(
2335
"GuestKernelInfo",
2336
TraceLoggingValue(m_seccompAvailable, "SeccompAvailable"),
2337
+ TraceLoggingValue(m_hvPciSwiotlbBase, "HvPciSwiotlbBase"),
2338
+ TraceLoggingValue(m_hvPciSwiotlbSize, "HvPciSwiotlbSize"),
2339
TraceLoggingValue(std::get<0>(m_kernelVersion), "Version"),
2340
TraceLoggingValue(std::get<1>(m_kernelVersion), "Revision"),
2341
TraceLoggingValue(std::get<2>(m_kernelVersion), "Minor"));