logging: add more settings to vm create begin / end events. (#13412)
* logging: add more settings to vm create begin / end events. * pr feedback, less string allocations' * Handle empty user module list differently * pr feedback --------- Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
Ben Hillis committed
Sep 8, 2025 at 15:32 UTC
36c077bd694f2123f83bef95952ee8271da60113
3 files changed
+29
-28
src/windows/common/WslCoreConfig.cpp
+12
-9
@@ -107,8 +107,8 @@ void wsl::core::Config::ParseConfigFile(_In_opt_ LPCWSTR ConfigFilePath, _In_opt
107
ConfigKey(ConfigSetting::MaxCrashDumpCount, MaxCrashDumpCount),
108
ConfigKey(ConfigSetting::DistributionInstallPath, DefaultDistributionLocation),
109
ConfigKey(ConfigSetting::InstanceIdleTimeout, InstanceIdleTimeout),
110
- ConfigKey(ConfigSetting::LoadDefaultKernelModules, LoadDefaultKernelModules, &loadKernelModulesPresence),
111
- ConfigKey(ConfigSetting::LoadKernelModules, userKernelModules, &loadKernelModulesPresence),
110
+ ConfigKey(ConfigSetting::LoadDefaultKernelModules, LoadDefaultKernelModules, &LoadKernelModulesPresence),
111
+ ConfigKey(ConfigSetting::LoadKernelModules, userKernelModules, &LoadKernelModulesPresence),
112
113
// Features that were previously experimental (the old header is maintained for compatibility).
114
ConfigKey({ConfigSetting::NetworkingMode, ConfigSetting::Experimental::NetworkingMode}, wsl::core::NetworkingModes, NetworkingMode, &NetworkingModePresence),
@@ -194,15 +194,18 @@ void wsl::core::Config::ParseConfigFile(_In_opt_ LPCWSTR ConfigFilePath, _In_opt
194
DefaultDistributionLocation = wsl::windows::common::filesystem::GetLocalAppDataPath(UserToken) / "wsl";
195
}
196
197
- if (!LoadDefaultKernelModules)
198
- {
199
- KernelModulesList.clear();
200
- }
197
+ auto kernelModules =
198
+ LoadDefaultKernelModules ? std::vector<std::wstring>{L"tun", L"ip_tables", L"br_netfilter"} : std::vector<std::wstring>{};
199
202
- for (auto& e : wsl::shared::string::Split(userKernelModules, L','))
200
+ if (!userKernelModules.empty())
201
{
204
- KernelModulesList.emplace_back(std::move(e));
202
+ for (const auto& e : wsl::shared::string::Split(userKernelModules, L','))
203
+ {
204
+ kernelModules.emplace_back(std::move(e));
205
+ }
206
}
207
+
208
+ KernelModulesList = wsl::shared::string::Join(kernelModules, L',');
209
}
210
211
void wsl::core::Config::SaveNetworkingSettings(_In_opt_ HANDLE UserToken) const
@@ -287,7 +290,7 @@ void wsl::core::Config::Initialize(_In_opt_ HANDLE UserToken)
290
{
291
// Determine the maximum number of processors that can be added to the VM.
292
// If the user did not supply a processor count, use the maximum.
290
- const auto MaximumProcessorCount = wsl::windows::common::wslutil::GetLogicalProcessorCount();
293
+ MaximumProcessorCount = wsl::windows::common::wslutil::GetLogicalProcessorCount();
294
if (ProcessorCount <= 0)
295
{
296
ProcessorCount = MaximumProcessorCount;
src/windows/common/WslCoreConfig.h
+16
-18
@@ -14,26 +14,25 @@ Abstract:
14
15
#pragma once
16
17
-#define T_SET(c, n) TraceLoggingValue(!(c).n.empty(), "config." #n "Set")
18
-
19
-#define T_PRESENT(val, n) TraceLoggingValue(val == ConfigKeyPresence::Present, "config." #n "Set")
20
-
21
-#define T_STRING(c, n) TraceLoggingValue(wsl::core::ToString((c).n), "config." #n "String")
22
-
23
-#define T_VALUE(c, n) TraceLoggingValue((c).n, "config." #n)
17
+#define T_ENUM(c, n) TraceLoggingValue(wsl::core::ToString((c).n), #n)
18
+#define T_PRESENT(c, n) TraceLoggingValue((c).n == ConfigKeyPresence::Present, #n)
19
+#define T_SET(c, n) TraceLoggingValue(!(c).n.empty(), #n "Set")
20
+#define T_STRING(c, n) TraceLoggingValue((c).n.c_str(), #n)
21
+#define T_VALUE(c, n) TraceLoggingValue((c).n, #n)
22
23
#define CONFIG_TELEMETRY(c) \
24
T_VALUE(c, BestEffortDnsParsing), T_VALUE(c, DhcpTimeout), T_VALUE(c, EnableAutoProxy), T_VALUE(c, EnableDebugConsole), \
27
- T_VALUE(c, EnableDhcp), T_VALUE(c, EnableDnsProxy), T_VALUE(c, EnableDnsTunneling), T_VALUE(c, EnableGpuSupport), \
28
- T_VALUE(c, EnableGuiApps), T_VALUE(c, EnableHardwarePerformanceCounters), T_VALUE(c, EnableHostAddressLoopback), \
29
- T_VALUE(c, EnableHostFileSystemAccess), T_VALUE(c, EnableIpv6), T_SET(c, KernelModulesPath), \
25
+ T_VALUE(c, EnableDebugShell), T_VALUE(c, EnableDhcp), T_VALUE(c, EnableDnsProxy), T_VALUE(c, EnableDnsTunneling), \
26
+ T_VALUE(c, EnableGpuSupport), T_VALUE(c, EnableGuiApps), T_VALUE(c, EnableHardwarePerformanceCounters), \
27
+ T_VALUE(c, EnableHostAddressLoopback), T_VALUE(c, EnableHostFileSystemAccess), T_VALUE(c, EnableIpv6), \
28
T_VALUE(c, EnableLocalhostRelay), T_VALUE(c, EnableNestedVirtualization), T_VALUE(c, EnableSafeMode), \
29
T_VALUE(c, EnableSparseVhd), T_VALUE(c, EnableVirtio), T_VALUE(c, EnableVirtio9p), T_VALUE(c, EnableVirtioFs), \
32
- T_STRING(c, FirewallConfigPresence), T_VALUE(c, KernelBootTimeout), T_SET(c, KernelCommandLine), \
33
- T_VALUE(c, KernelDebugPort), T_SET(c, KernelPath), T_PRESENT((c).loadKernelModulesPresence, loadKernelModules), \
34
- T_VALUE(c, LoadDefaultKernelModules), T_STRING(c, MemoryReclaim), T_VALUE(c, MemorySizeBytes), \
35
- T_VALUE(c, MountDeviceTimeout), T_STRING(c, NetworkingMode), T_VALUE(c, ProcessorCount), T_SET(c, SwapFilePath), \
36
- T_VALUE(c, SwapSizeBytes), T_SET(c, SystemDistroPath), T_VALUE(c, VhdSizeBytes), T_VALUE(c, VmIdleTimeout), T_SET(c, VmSwitch)
30
+ T_ENUM(c, FirewallConfigPresence), T_VALUE(c, KernelBootTimeout), T_SET(c, KernelCommandLine), \
31
+ T_VALUE(c, KernelDebugPort), T_SET(c, KernelModulesPath), T_STRING(c, KernelModulesList), T_SET(c, KernelPath), \
32
+ T_VALUE(c, LoadDefaultKernelModules), T_PRESENT(c, LoadKernelModulesPresence), T_VALUE(c, MaximumMemorySizeBytes), \
33
+ T_VALUE(c, MaximumProcessorCount), T_ENUM(c, MemoryReclaim), T_VALUE(c, MemorySizeBytes), T_VALUE(c, MountDeviceTimeout), \
34
+ T_ENUM(c, NetworkingMode), T_VALUE(c, ProcessorCount), T_SET(c, SwapFilePath), T_VALUE(c, SwapSizeBytes), \
35
+ T_SET(c, SystemDistroPath), T_VALUE(c, VhdSizeBytes), T_VALUE(c, VmIdleTimeout), T_SET(c, VmSwitch)
36
37
namespace wsl::core {
38
constexpr auto ToString(ConfigKeyPresence key)
@@ -305,11 +304,10 @@ struct Config
304
void SaveNetworkingSettings(_In_opt_ HANDLE UserToken) const;
305
static unsigned long WriteConfigFile(_In_ LPCWSTR ConfigFilePath, _In_ ConfigKey KeyToWrite, _In_ bool RemoveKey = false);
306
308
- // Values set in ParseConfigFile
307
std::filesystem::path KernelPath;
308
std::wstring KernelCommandLine;
309
+ std::wstring KernelModulesList;
310
std::filesystem::path KernelModulesPath;
312
- std::vector<std::wstring> KernelModulesList = {L"tun", L"ip_tables", L"br_netfilter"};
311
UINT64 MemorySizeBytes = 0;
312
UINT64 MaximumMemorySizeBytes = 0;
313
int ProcessorCount = 0;
@@ -320,7 +318,7 @@ struct Config
318
std::filesystem::path SwapFilePath;
319
bool EnableLocalhostRelay = true;
320
ConfigKeyPresence LocalhostRelayConfigPresence = ConfigKeyPresence::Absent;
323
- ConfigKeyPresence loadKernelModulesPresence = ConfigKeyPresence::Absent;
321
+ ConfigKeyPresence LoadKernelModulesPresence = ConfigKeyPresence::Absent;
322
bool LoadDefaultKernelModules = true;
323
bool EnableNestedVirtualization = !shared::Arm64 && windows::common::helpers::IsWindows11OrAbove();
324
bool EnableVirtio9p = false;
src/windows/service/exe/WslCoreVm.cpp
+1
-1
@@ -545,7 +545,7 @@ void WslCoreVm::Initialize(const GUID& VmId, const wil::shared_handle& UserToken
545
message->DefaultKernel = m_defaultKernel;
546
message->KernelModulesDeviceId = modulesLun;
547
message.WriteString(message->HostnameOffset, wsl::windows::common::filesystem::GetLinuxHostName());
548
- message.WriteString(message->KernelModulesListOffset, wsl::shared::string::Join<wchar_t>(m_vmConfig.KernelModulesList, L','));
548
+ message.WriteString(message->KernelModulesListOffset, m_vmConfig.KernelModulesList);
549
message->DnsTunnelingIpAddress = m_vmConfig.DnsTunnelingIpAddress.value_or(0);
550
551
m_miniInitChannel.SendMessage<LX_MINI_INIT_EARLY_CONFIG_MESSAGE>(message.Span());