Mount the GPU executables in gpu-enabled containers (#40896)
* Bind mount GPU executables to /usr/bin * Cleanup diff * Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Format --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Blue committed
Jun 25, 2026 at 14:41 UTC
db9d3a8c8eb8cc932c7f4fd0510a006b5c424708
2 files changed
+41
src/linux/init/WSLCInit.cpp
+19
@@ -152,6 +152,25 @@ try
152
const char* const ldArgv[] = {LDCONFIG_COMMAND, nullptr};
153
THROW_LAST_ERROR_IF(UtilCreateProcessAndWait(ldArgv[0], ldArgv) < 0);
154
155
+ constexpr auto c_binPath = "/usr/bin";
156
+ if (std::filesystem::is_directory(LXSS_LIB_PATH))
157
+ {
158
+ for (const auto& entry : std::filesystem::directory_iterator(LXSS_LIB_PATH))
159
+ {
160
+ const auto fileName = entry.path().filename().string();
161
+ if (fileName.find(".so") != std::string::npos || !entry.is_regular_file())
162
+ {
163
+ continue;
164
+ }
165
+
166
+ const auto target = std::format("{}/{}", c_binPath, fileName);
167
+ if (UtilMountFile(entry.path().c_str(), target.c_str()) < 0)
168
+ {
169
+ LOG_ERROR("UtilMountFile({}, {}) failed {}", entry.path().c_str(), target, errno);
170
+ }
171
+ }
172
+ }
173
+
174
return 0;
175
}
176
CATCH_RETURN_ERRNO()
test/windows/WSLCTests.cpp
+22
@@ -3718,6 +3718,28 @@ class WSLCTests
3718
// Validate that the dynamic linker is configured to resolve the WSL GPU libraries.
3719
expect({"/bin/sh", "-c", "cat /etc/ld.so.conf.d/ld.wsl.conf"}, 0, {{1, "/usr/lib/wsl/lib\n"}});
3720
expect({"/bin/sh", "-c", "ldconfig -p | grep -q ' => /usr/lib/wsl/lib/'"}, 0);
3721
+
3722
+ std::vector<std::string> expectedBinaries;
3723
+ for (const auto& entry : std::filesystem::directory_iterator("C:\\Windows\\system32\\lxss\\lib"))
3724
+ {
3725
+ const auto fileName = entry.path().filename().wstring();
3726
+ if (entry.is_regular_file() && fileName.find(L".so") == std::wstring::npos)
3727
+ {
3728
+ expectedBinaries.push_back(wsl::shared::string::WideToMultiByte(fileName));
3729
+ }
3730
+ }
3731
+
3732
+ if (expectedBinaries.empty())
3733
+ {
3734
+ LogWarning("No executables found in C:\\Windows\\system32\\lxss\\lib. Skipping GPU executable bind mount test");
3735
+ }
3736
+ else
3737
+ {
3738
+ for (const auto& e : expectedBinaries)
3739
+ {
3740
+ expect({"test", "-x", std::format("/usr/bin/{}", e)}, 0);
3741
+ }
3742
+ }
3743
}
3744
3745
// Validate that containers without the GPU flag do not have GPU resources.