Skip to content

Commit 1390e64

Browse files
authored
cleanup: add handling for product-specific virtio networking class IDs. (#13822)
1 parent c64eb18 commit 1390e64

File tree

7 files changed

+30
-39
lines changed

7 files changed

+30
-39
lines changed

packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<package id="Microsoft.WSL.bsdtar" version="0.0.2-2" />
1919
<package id="Microsoft.WSL.Dependencies.amd64fre" version="10.0.27820.1000-250318-1700.rs-base2-hyp" targetFramework="native" />
2020
<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" />
2222
<package id="Microsoft.WSL.Kernel" version="6.6.114.1-1" targetFramework="native" />
2323
<package id="Microsoft.WSL.LinuxSdk" version="1.20.0" targetFramework="native" />
2424
<package id="Microsoft.WSL.TestDistro" version="2.5.7-47" />

src/windows/common/GuestDeviceManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void GuestDeviceManager::AddSharedMemoryDevice(_In_ const GUID& ImplementationCl
7070
static constexpr auto VIRTIO_FS_FLAGS_SHMEM_SIZE_SHIFT = 16;
7171
UINT32 flags = (SizeMb << VIRTIO_FS_FLAGS_SHMEM_SIZE_SHIFT);
7272
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);
7474
m_objectDirectories.emplace_back(std::move(objectLifetime));
7575
}
7676

src/windows/common/GuestDeviceManager.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88
#define VIRTIO_FS_FLAGS_TYPE_FILES 0x8000
99
#define VIRTIO_FS_FLAGS_TYPE_SECTIONS 0x4000
1010

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-
1711
inline const std::wstring c_defaultDeviceTag = L"default";
1812

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+
1918
//
2019
// Provides synchronized access to guest device operations.
2120
//

src/windows/common/VirtioNetworking.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ using wsl::core::VirtioNetworking;
1414
static constexpr auto c_loopbackDeviceName = TEXT(LX_INIT_LOOPBACK_DEVICE_NAME);
1515

1616
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) :
1818
m_guestDeviceManager(std::move(guestDeviceManager)),
1919
m_userToken(std::move(userToken)),
2020
m_gnsChannel(std::move(gnsChannel)),
21-
m_enableLocalhostRelay(enableLocalhostRelay)
21+
m_enableLocalhostRelay(enableLocalhostRelay),
22+
m_virtioNetworkClsid(classId)
2223
{
2324
}
2425

@@ -31,7 +32,6 @@ VirtioNetworking::~VirtioNetworking()
3132
}
3233

3334
void VirtioNetworking::Initialize()
34-
try
3535
{
3636
m_networkSettings = GetHostEndpointSettings();
3737

@@ -80,7 +80,7 @@ try
8080

8181
// Add virtio net adapter to guest
8282
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());
8484

8585
hns::HNSEndpoint endpointProperties;
8686
endpointProperties.ID = m_adapterId;
@@ -122,13 +122,12 @@ try
122122

123123
THROW_IF_WIN32_ERROR(NotifyNetworkConnectivityHintChange(&VirtioNetworking::OnNetworkConnectivityChange, this, true, &m_networkNotifyHandle));
124124
}
125-
CATCH_LOG()
126125

127126
void VirtioNetworking::SetupLoopbackDevice()
128127
{
129128
m_localhostAdapterId = m_guestDeviceManager->AddGuestDevice(
130-
c_virtioNetworkDeviceId,
131-
c_virtioNetworkClsid,
129+
VIRTIO_NET_DEVICE_ID,
130+
m_virtioNetworkClsid,
132131
c_loopbackDeviceName,
133132
nullptr,
134133
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
196195
localAddr.Ipv6.sin6_port = addr.Ipv6.sin6_port;
197196
}
198197
}
199-
result = ModifyOpenPorts(c_virtioNetworkClsid, c_loopbackDeviceName, localAddr, protocol, allocate);
198+
result = ModifyOpenPorts(c_loopbackDeviceName, localAddr, protocol, allocate);
200199
LOG_HR_IF_MSG(E_FAIL, result != S_OK, "Failure adding localhost relay port %d", localAddr.Ipv4.sin_port);
201200
}
202201

203202
if (!loopback)
204203
{
205-
const int localResult = ModifyOpenPorts(c_virtioNetworkClsid, L"eth0", addr, protocol, allocate);
204+
const int localResult = ModifyOpenPorts(L"eth0", addr, protocol, allocate);
206205
LOG_HR_IF_MSG(E_FAIL, localResult != S_OK, "Failure adding relay port %d", addr.Ipv4.sin_port);
207206
if (result == 0)
208207
{
@@ -213,7 +212,7 @@ HRESULT VirtioNetworking::HandlePortNotification(const SOCKADDR_INET& addr, int
213212
return result;
214213
}
215214

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
217216
{
218217
if (protocol != IPPROTO_TCP && protocol != IPPROTO_UDP)
219218
{
@@ -229,7 +228,7 @@ int VirtioNetworking::ModifyOpenPorts(_In_ const GUID& clsid, _In_ PCWSTR tag, _
229228
}
230229

231230
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);
233232
if (server)
234233
{
235234
std::wstring portString = std::format(L"tag={};port_number={}", tag, addr.Ipv4.sin_port);

src/windows/common/VirtioNetworking.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace wsl::core {
1313
class VirtioNetworking : public INetworkingEngine
1414
{
1515
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);
1717
~VirtioNetworking();
1818

1919
// Note: This class cannot be moved because m_networkNotifyHandle captures a 'this' pointer.
@@ -35,7 +35,7 @@ class VirtioNetworking : public INetworkingEngine
3535
static std::optional<ULONGLONG> FindVirtioInterfaceLuid(const SOCKADDR_INET& virtioAddress, const NL_NETWORK_CONNECTIVITY_HINT& currentConnectivityHint);
3636

3737
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;
3939
void RefreshGuestConnection(NL_NETWORK_CONNECTIVITY_HINT hint) noexcept;
4040
void SetupLoopbackDevice();
4141
void UpdateDns(wsl::shared::hns::DNS&& dnsSettings);
@@ -51,18 +51,14 @@ class VirtioNetworking : public INetworkingEngine
5151
bool m_enableLocalhostRelay;
5252
GUID m_localhostAdapterId;
5353
GUID m_adapterId;
54+
GUID m_virtioNetworkClsid;
5455

5556
std::optional<ULONGLONG> m_interfaceLuid;
5657
ULONG m_networkMtu = 0;
5758
std::optional<wsl::core::networking::HostDnsInfo> m_dnsInfo;
5859

5960
// Note: this field must be destroyed first to stop the callbacks before any other field is destroyed.
6061
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}};
6662
};
6763

6864
} // namespace wsl::core

src/windows/service/exe/WslCoreVm.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ using namespace std::string_literals;
3939
// Start of unaddressable memory if guest only supports the minimum 36-bit addressing.
4040
#define MAX_36_BIT_PAGE_IN_MB (0x1000000000 / _1MB)
4141

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-
4642
// Version numbers for various functionality that was backported.
4743
#define NICKEL_BUILD_FLOOR 22350
4844
#define VIRTIO_SERIAL_CONSOLE_COBALT_RELEASE_UBR 40
@@ -53,6 +49,12 @@ DEFINE_GUID(VIRTIO_PMEM_DEVICE_ID, 0xEDBB24BB, 0x5E19, 0x40F4, 0x8A, 0x0F, 0x82,
5349
#define WSLG_SHARED_MEMORY_SIZE_MB 8192
5450
#define PAGE_SIZE 0x1000
5551

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+
5658
static constexpr size_t c_bootEntropy = 0x1000;
5759
static constexpr auto c_localDevicesKey = L"SOFTWARE\\Microsoft\\Terminal Server Client\\LocalDevices";
5860
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
596598
else if (m_vmConfig.NetworkingMode == NetworkingMode::VirtioProxy)
597599
{
598600
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);
600602
}
601603
else if (m_vmConfig.NetworkingMode == NetworkingMode::Bridged)
602604
{
@@ -1792,7 +1794,7 @@ void WslCoreVm::InitializeGuest()
17921794
try
17931795
{
17941796
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());
17961798
m_sharedMemoryRoot = std::format(L"WSL\\{}\\wslg", m_machineId);
17971799
}
17981800
CATCH_LOG()
@@ -2145,8 +2147,8 @@ std::wstring WslCoreVm::AddVirtioFsShare(_In_ bool Admin, _In_ PCWSTR Path, _In_
21452147
WI_ASSERT(!FindVirtioFsShare(tag.c_str(), Admin));
21462148

21472149
(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,
21502152
tag.c_str(),
21512153
key.OptionsString().c_str(),
21522154
sharePath.c_str(),

src/windows/service/exe/WslCoreVm.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ inline constexpr auto c_optionsValueName = L"Options";
4040
inline constexpr auto c_typeValueName = L"Type";
4141
inline constexpr auto c_mountNameValueName = L"Name";
4242

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-
4843
namespace wrl = Microsoft::WRL;
4944

5045
/// <summary>

0 commit comments

Comments
 (0)