@samitouri / QOSAMI-WSL / commits / 1390e644

cleanup: add handling for product-specific virtio networking class IDs. (#13822)

Ben Hillis committed Dec 3, 2025 at 18:55 UTC 1390e644fbd300f18732e1cdb5eebb164e5c10a2
7 files changed +30 -39
packages.config
+1 -1
@@ -18,7 +18,7 @@
18 <package id="Microsoft.WSL.bsdtar" version="0.0.2-2" />
19 <package id="Microsoft.WSL.Dependencies.amd64fre" version="10.0.27820.1000-250318-1700.rs-base2-hyp" targetFramework="native" />
20 <package id="Microsoft.WSL.Dependencies.arm64fre" version="10.0.27820.1000-250318-1700.rs-base2-hyp" targetFramework="native" />
21 - <package id="Microsoft.WSL.DeviceHost" version="1.0.0-20251201.1" />
21 + <package id="Microsoft.WSL.DeviceHost" version="1.0.0-20251202.1" />
22 <package id="Microsoft.WSL.Kernel" version="6.6.114.1-1" targetFramework="native" />
23 <package id="Microsoft.WSL.LinuxSdk" version="1.20.0" targetFramework="native" />
24 <package id="Microsoft.WSL.TestDistro" version="2.5.7-47" />
src/windows/common/GuestDeviceManager.cpp
+1 -1
@@ -70,7 +70,7 @@ void GuestDeviceManager::AddSharedMemoryDevice(_In_ const GUID& ImplementationCl
70 static constexpr auto VIRTIO_FS_FLAGS_SHMEM_SIZE_SHIFT = 16;
71 UINT32 flags = (SizeMb << VIRTIO_FS_FLAGS_SHMEM_SIZE_SHIFT);
72 WI_SetFlag(flags, VIRTIO_FS_FLAGS_TYPE_SECTIONS);
73 - (void)AddHdvShareWithOptions(VIRTIO_VIRTIOFS_DEVICE_ID, ImplementationClsid, Tag, {}, objectLifetime.Path.c_str(), flags, UserToken);
73 + (void)AddHdvShareWithOptions(VIRTIO_FS_DEVICE_ID, ImplementationClsid, Tag, {}, objectLifetime.Path.c_str(), flags, UserToken);
74 m_objectDirectories.emplace_back(std::move(objectLifetime));
75 }
76
src/windows/common/GuestDeviceManager.h
+5 -6
@@ -8,14 +8,13 @@
8 #define VIRTIO_FS_FLAGS_TYPE_FILES 0x8000
9 #define VIRTIO_FS_FLAGS_TYPE_SECTIONS 0x4000
10
11 -// {872270E1-A899-4AF6-B454-7193634435AD}
12 -DEFINE_GUID(VIRTIO_VIRTIOFS_DEVICE_ID, 0x872270E1, 0xA899, 0x4AF6, 0xB4, 0x54, 0x71, 0x93, 0x63, 0x44, 0x35, 0xAD);
13 -
14 -// {ABB755FC-1B86-4255-83E2-E5787ABCF6C2}
15 -DEFINE_GUID(VIRTIO_PMEM_CLASS_ID, 0xABB755FC, 0x1B86, 0x4255, 0x83, 0xe2, 0xe5, 0x78, 0x7a, 0xbc, 0xf6, 0xc2);
16 -
11 inline const std::wstring c_defaultDeviceTag = L"default";
12
13 +// These device types are implemented by the external wsldevicehost vdev.
14 +DEFINE_GUID(VIRTIO_FS_DEVICE_ID, 0x872270E1, 0xA899, 0x4AF6, 0xB4, 0x54, 0x71, 0x93, 0x63, 0x44, 0x35, 0xAD); // {872270E1-A899-4AF6-B454-7193634435AD}
15 +DEFINE_GUID(VIRTIO_NET_DEVICE_ID, 0xF07010D0, 0x0EA9, 0x447F, 0x88, 0xEF, 0xBD, 0x95, 0x2A, 0x4D, 0x2F, 0x14); // {F07010D0-0EA9-447F-88EF-BD952A4D2F14}
16 +DEFINE_GUID(VIRTIO_PMEM_DEVICE_ID, 0xEDBB24BB, 0x5E19, 0x40F4, 0x8A, 0x0F, 0x82, 0x24, 0x31, 0x30, 0x64, 0xFD); // {EDBB24BB-5E19-40F4-8A0F-8224313064FD}
17 +
18 //
19 // Provides synchronized access to guest device operations.
20 //
src/windows/common/VirtioNetworking.cpp
+10 -11
@@ -14,11 +14,12 @@ using wsl::core::VirtioNetworking;
14 static constexpr auto c_loopbackDeviceName = TEXT(LX_INIT_LOOPBACK_DEVICE_NAME);
15
16 VirtioNetworking::VirtioNetworking(
17 - GnsChannel&& gnsChannel, bool enableLocalhostRelay, std::shared_ptr<GuestDeviceManager> guestDeviceManager, wil::shared_handle userToken) :
17 + GnsChannel&& gnsChannel, bool enableLocalhostRelay, std::shared_ptr<GuestDeviceManager> guestDeviceManager, GUID classId, wil::shared_handle userToken) :
18 m_guestDeviceManager(std::move(guestDeviceManager)),
19 m_userToken(std::move(userToken)),
20 m_gnsChannel(std::move(gnsChannel)),
21 - m_enableLocalhostRelay(enableLocalhostRelay)
21 + m_enableLocalhostRelay(enableLocalhostRelay),
22 + m_virtioNetworkClsid(classId)
23 {
24 }
25
@@ -31,7 +32,6 @@ VirtioNetworking::~VirtioNetworking()
32 }
33
34 void VirtioNetworking::Initialize()
34 -try
35 {
36 m_networkSettings = GetHostEndpointSettings();
37
@@ -80,7 +80,7 @@ try
80
81 // Add virtio net adapter to guest
82 m_adapterId = m_guestDeviceManager->AddGuestDevice(
83 - c_virtioNetworkDeviceId, c_virtioNetworkClsid, L"eth0", nullptr, device_options.str().c_str(), 0, m_userToken.get());
83 + VIRTIO_NET_DEVICE_ID, m_virtioNetworkClsid, L"eth0", nullptr, device_options.str().c_str(), 0, m_userToken.get());
84
85 hns::HNSEndpoint endpointProperties;
86 endpointProperties.ID = m_adapterId;
@@ -122,13 +122,12 @@ try
122
123 THROW_IF_WIN32_ERROR(NotifyNetworkConnectivityHintChange(&VirtioNetworking::OnNetworkConnectivityChange, this, true, &m_networkNotifyHandle));
124 }
125 -CATCH_LOG()
125
126 void VirtioNetworking::SetupLoopbackDevice()
127 {
128 m_localhostAdapterId = m_guestDeviceManager->AddGuestDevice(
130 - c_virtioNetworkDeviceId,
131 - c_virtioNetworkClsid,
129 + VIRTIO_NET_DEVICE_ID,
130 + m_virtioNetworkClsid,
131 c_loopbackDeviceName,
132 nullptr,
133 L"client_ip=127.0.0.1;client_mac=00:11:22:33:44:55",
@@ -196,13 +195,13 @@ HRESULT VirtioNetworking::HandlePortNotification(const SOCKADDR_INET& addr, int
195 localAddr.Ipv6.sin6_port = addr.Ipv6.sin6_port;
196 }
197 }
199 - result = ModifyOpenPorts(c_virtioNetworkClsid, c_loopbackDeviceName, localAddr, protocol, allocate);
198 + result = ModifyOpenPorts(c_loopbackDeviceName, localAddr, protocol, allocate);
199 LOG_HR_IF_MSG(E_FAIL, result != S_OK, "Failure adding localhost relay port %d", localAddr.Ipv4.sin_port);
200 }
201
202 if (!loopback)
203 {
205 - const int localResult = ModifyOpenPorts(c_virtioNetworkClsid, L"eth0", addr, protocol, allocate);
204 + const int localResult = ModifyOpenPorts(L"eth0", addr, protocol, allocate);
205 LOG_HR_IF_MSG(E_FAIL, localResult != S_OK, "Failure adding relay port %d", addr.Ipv4.sin_port);
206 if (result == 0)
207 {
@@ -213,7 +212,7 @@ HRESULT VirtioNetworking::HandlePortNotification(const SOCKADDR_INET& addr, int
212 return result;
213 }
214
216 -int VirtioNetworking::ModifyOpenPorts(_In_ const GUID& clsid, _In_ PCWSTR tag, _In_ const SOCKADDR_INET& addr, _In_ int protocol, _In_ bool isOpen) const
215 +int VirtioNetworking::ModifyOpenPorts(_In_ PCWSTR tag, _In_ const SOCKADDR_INET& addr, _In_ int protocol, _In_ bool isOpen) const
216 {
217 if (protocol != IPPROTO_TCP && protocol != IPPROTO_UDP)
218 {
@@ -229,7 +228,7 @@ int VirtioNetworking::ModifyOpenPorts(_In_ const GUID& clsid, _In_ PCWSTR tag, _
228 }
229
230 auto lock = m_lock.lock_exclusive();
232 - const auto server = m_guestDeviceManager->GetRemoteFileSystem(clsid, c_defaultDeviceTag);
231 + const auto server = m_guestDeviceManager->GetRemoteFileSystem(m_virtioNetworkClsid, c_defaultDeviceTag);
232 if (server)
233 {
234 std::wstring portString = std::format(L"tag={};port_number={}", tag, addr.Ipv4.sin_port);
src/windows/common/VirtioNetworking.h
+3 -7
@@ -13,7 +13,7 @@ namespace wsl::core {
13 class VirtioNetworking : public INetworkingEngine
14 {
15 public:
16 - VirtioNetworking(GnsChannel&& gnsChannel, bool enableLocalhostRelay, std::shared_ptr<GuestDeviceManager> guestDeviceManager, wil::shared_handle userToken);
16 + VirtioNetworking(GnsChannel&& gnsChannel, bool enableLocalhostRelay, std::shared_ptr<GuestDeviceManager> guestDeviceManager, GUID classId, wil::shared_handle userToken);
17 ~VirtioNetworking();
18
19 // Note: This class cannot be moved because m_networkNotifyHandle captures a 'this' pointer.
@@ -35,7 +35,7 @@ private:
35 static std::optional<ULONGLONG> FindVirtioInterfaceLuid(const SOCKADDR_INET& virtioAddress, const NL_NETWORK_CONNECTIVITY_HINT& currentConnectivityHint);
36
37 HRESULT HandlePortNotification(const SOCKADDR_INET& addr, int protocol, bool allocate) const noexcept;
38 - int ModifyOpenPorts(_In_ const GUID& clsid, _In_ PCWSTR tag, _In_ const SOCKADDR_INET& addr, _In_ int protocol, _In_ bool isOpen) const;
38 + int ModifyOpenPorts(_In_ PCWSTR tag, _In_ const SOCKADDR_INET& addr, _In_ int protocol, _In_ bool isOpen) const;
39 void RefreshGuestConnection(NL_NETWORK_CONNECTIVITY_HINT hint) noexcept;
40 void SetupLoopbackDevice();
41 void UpdateDns(wsl::shared::hns::DNS&& dnsSettings);
@@ -51,6 +51,7 @@ private:
51 bool m_enableLocalhostRelay;
52 GUID m_localhostAdapterId;
53 GUID m_adapterId;
54 + GUID m_virtioNetworkClsid;
55
56 std::optional<ULONGLONG> m_interfaceLuid;
57 ULONG m_networkMtu = 0;
@@ -58,11 +59,6 @@ private:
59
60 // Note: this field must be destroyed first to stop the callbacks before any other field is destroyed.
61 networking::unique_notify_handle m_networkNotifyHandle;
61 -
62 - // 16479D2E-F0C3-4DBA-BF7A-04FFF0892B07
63 - static constexpr GUID c_virtioNetworkClsid = {0x16479D2E, 0xF0C3, 0x4DBA, {0xBF, 0x7A, 0x04, 0xFF, 0xF0, 0x89, 0x2B, 0x07}};
64 - // F07010D0-0EA9-447F-88EF-BD952A4D2F14
65 - static constexpr GUID c_virtioNetworkDeviceId = {0xF07010D0, 0x0EA9, 0x447F, {0x88, 0xEF, 0xBD, 0x95, 0x2A, 0x4D, 0x2F, 0x14}};
62 };
63
64 } // namespace wsl::core
src/windows/service/exe/WslCoreVm.cpp
+10 -8
@@ -39,10 +39,6 @@ using namespace std::string_literals;
39 // Start of unaddressable memory if guest only supports the minimum 36-bit addressing.
40 #define MAX_36_BIT_PAGE_IN_MB (0x1000000000 / _1MB)
41
42 -// This device type is implemented by the external virtio-pmem vdev.
43 -// {EDBB24BB-5E19-40F4-8A0F-8224313064FD}
44 -DEFINE_GUID(VIRTIO_PMEM_DEVICE_ID, 0xEDBB24BB, 0x5E19, 0x40F4, 0x8A, 0x0F, 0x82, 0x24, 0x31, 0x30, 0x64, 0xFD);
45 -
42 // Version numbers for various functionality that was backported.
43 #define NICKEL_BUILD_FLOOR 22350
44 #define VIRTIO_SERIAL_CONSOLE_COBALT_RELEASE_UBR 40
@@ -53,6 +49,12 @@ DEFINE_GUID(VIRTIO_PMEM_DEVICE_ID, 0xEDBB24BB, 0x5E19, 0x40F4, 0x8A, 0x0F, 0x82,
49 #define WSLG_SHARED_MEMORY_SIZE_MB 8192
50 #define PAGE_SIZE 0x1000
51
52 +// WSL-specific virtio device class IDs.
53 +DEFINE_GUID(VIRTIO_FS_ADMIN_CLASS_ID, 0x7E6AD219, 0xD1B3, 0x42D5, 0xB8, 0xEE, 0xD9, 0x63, 0x24, 0xE6, 0x4F, 0xF6); // {7E6AD219-D1B3-42D5-B8EE-D96324E64FF6}
54 +DEFINE_GUID(VIRTIO_FS_CLASS_ID, 0x60285AE6, 0xAAF3, 0x4456, 0xB4, 0x44, 0xA6, 0xC2, 0xD0, 0xDE, 0xDA, 0x38); // {60285AE6-AAF3-4456-B444-A6C2D0DEDA38}
55 +DEFINE_GUID(VIRTIO_NET_CLASS_ID, 0x16479D2E, 0xF0C3, 0x4DBA, 0xBF, 0x7A, 0x04, 0xFF, 0xF0, 0x89, 0x2B, 0x07); // {16479D2E-F0C3-4DBA-BF7A-04FFF0892B07}
56 +DEFINE_GUID(VIRTIO_PMEM_CLASS_ID, 0xABB755FC, 0x1B86, 0x4255, 0x83, 0xE2, 0xE5, 0x78, 0x7A, 0xBC, 0xF6, 0xC2); // {ABB755FC-1B86-4255-83E2-E5787ABCF6C2}
57 +
58 static constexpr size_t c_bootEntropy = 0x1000;
59 static constexpr auto c_localDevicesKey = L"SOFTWARE\\Microsoft\\Terminal Server Client\\LocalDevices";
60 static constexpr std::pair<uint32_t, uint32_t> c_schemaVersionNickel{2, 7};
@@ -596,7 +598,7 @@ void WslCoreVm::Initialize(const GUID& VmId, const wil::shared_handle& UserToken
598 else if (m_vmConfig.NetworkingMode == NetworkingMode::VirtioProxy)
599 {
600 m_networkingEngine = std::make_unique<wsl::core::VirtioNetworking>(
599 - std::move(gnsChannel), m_vmConfig.EnableLocalhostRelay, m_guestDeviceManager, m_userToken);
601 + std::move(gnsChannel), m_vmConfig.EnableLocalhostRelay, m_guestDeviceManager, VIRTIO_NET_CLASS_ID, m_userToken);
602 }
603 else if (m_vmConfig.NetworkingMode == NetworkingMode::Bridged)
604 {
@@ -1792,7 +1794,7 @@ void WslCoreVm::InitializeGuest()
1794 try
1795 {
1796 m_guestDeviceManager->AddSharedMemoryDevice(
1795 - c_virtiofsClassId, L"wslg", L"wslg", WSLG_SHARED_MEMORY_SIZE_MB, m_userToken.get());
1797 + VIRTIO_FS_CLASS_ID, L"wslg", L"wslg", WSLG_SHARED_MEMORY_SIZE_MB, m_userToken.get());
1798 m_sharedMemoryRoot = std::format(L"WSL\\{}\\wslg", m_machineId);
1799 }
1800 CATCH_LOG()
@@ -2145,8 +2147,8 @@ std::wstring WslCoreVm::AddVirtioFsShare(_In_ bool Admin, _In_ PCWSTR Path, _In_
2147 WI_ASSERT(!FindVirtioFsShare(tag.c_str(), Admin));
2148
2149 (void)m_guestDeviceManager->AddGuestDevice(
2148 - VIRTIO_VIRTIOFS_DEVICE_ID,
2149 - Admin ? c_virtiofsAdminClassId : c_virtiofsClassId,
2150 + VIRTIO_FS_DEVICE_ID,
2151 + Admin ? VIRTIO_FS_ADMIN_CLASS_ID : VIRTIO_FS_CLASS_ID,
2152 tag.c_str(),
2153 key.OptionsString().c_str(),
2154 sharePath.c_str(),
src/windows/service/exe/WslCoreVm.h
-5
@@ -40,11 +40,6 @@ inline constexpr auto c_optionsValueName = L"Options";
40 inline constexpr auto c_typeValueName = L"Type";
41 inline constexpr auto c_mountNameValueName = L"Name";
42
43 -static constexpr GUID c_virtiofsAdminClassId = {0x7e6ad219, 0xd1b3, 0x42d5, {0xb8, 0xee, 0xd9, 0x63, 0x24, 0xe6, 0x4f, 0xf6}};
44 -
45 -// {60285AE6-AAF3-4456-B444-A6C2D0DEDA38}
46 -static constexpr GUID c_virtiofsClassId = {0x60285ae6, 0xaaf3, 0x4456, {0xb4, 0x44, 0xa6, 0xc2, 0xd0, 0xde, 0xda, 0x38}};
47 -
43 namespace wrl = Microsoft::WRL;
44
45 /// <summary>