Expose kernel headers and perf to distributions - #41400
Expose kernel headers and perf to distributions#41400Ben Hillis (benhillis) wants to merge 2 commits into
Conversation
Mount kernel-matched headers and perf tooling from the artifacts VHD into each distribution, expose perf through the default environment, and cover the resulting paths and replacement behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: cdebc331-ad3e-492e-9591-c25587c859c5
There was a problem hiding this comment.
Pull request overview
This PR extends the unified kernel artifacts VHD integration to expose kernel-matched Linux headers and perf tooling inside WSL distributions, wiring the required mounts/env-vars through mini_init → distro init, and adding WSL2 tests + documentation to validate the behavior.
Changes:
- Add support to surface kernel headers at
/usr/src/linux-headers-$(uname -r)and ensure/lib/modules/$(uname -r)/buildpoints to them. - Add support to surface perf at
/usr/lib/linux-tools/$(uname -r), add it to defaultPATH, and setPERF_EXEC_PATH(plus optional shadowing of distro/usr/bin/perf). - Add WSL2 test coverage for header usability, perf execution, and “stale artifact” replacement across VM restarts.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/windows/UnitTests.cpp | Adds WSL2 coverage validating header presence/usability, perf availability, and restart behavior. |
| src/shared/inc/lxinitshared.h | Introduces new env-var names for kernel headers/perf temporary mounts and target paths. |
| src/linux/init/WslDistributionConfig.h | Adds KernelPerfPath plumbing so perf can be added to PATH / configured in the environment block. |
| src/linux/init/util.cpp | Strengthens UtilMountFile() by validating the source is a regular file before mounting. |
| src/linux/init/main.cpp | Binds headers/perf from the artifacts VHD and passes them through to distro init via env-vars. |
| src/linux/init/config.cpp | Moves temporary mounts into the distro namespace; sets up build link and perf shadowing + env exposure. |
| doc/docs/technical-documentation/boot-process.md | Documents the new kernel headers/perf exposure behavior during boot. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Correct the documented header target and directory fallback, and log failures while removing mount path environment variables. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: cdebc331-ad3e-492e-9591-c25587c859c5
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/linux/init/config.cpp:188
- MoveTemporaryMount constructs RemoveMountAndEnvironmentOnScopeExit, which caches m_mountPath from getenv(). In RemoveMountAndEnvironmentOnScopeExit::~RemoveMountAndEnvironmentOnScopeExit() (config.cpp:114-137), unsetenv(m_environmentName) happens before umount2(m_mountPath)/rmdir(m_mountPath). Because getenv() pointers can be invalidated by unsetenv/setenv, this can use a dangling pointer and attempt to unmount an invalid path (undefined behavior). Consider storing a std::string copy of the mount path (or unmounting before unsetenv) so cleanup is safe.
auto tempMount = RemoveMountAndEnvironmentOnScopeExit(MountEnvironmentName);
const char* target = tempMount ? getenv(PathEnvironmentName) : nullptr;
if (target == nullptr)
{
return;
src/linux/init/config.cpp:1198
- The comment says the distro file system is only modified when perf is present as a regular file, but the code uses stat("/usr/bin/perf"), which follows symlinks and will also modify the resolved target when /usr/bin/perf is a symlink to a regular file (as exercised by the new unit test). Please update the comment to match the actual behavior (or switch to lstat() if symlinked perf should be excluded).
// If the distro ships its own perf, shadow it with a bind mount so that the binary matching the
// running kernel is used.
//
// N.B. The distro's file system is only modified if perf is already present as a regular file.
// Distros without perf pick it up via $PATH instead.
Blue (OneBlue)
left a comment
There was a problem hiding this comment.
LGTM, one minor comment
| VERIFY_ARE_EQUAL( | ||
| LxsstuLaunchWsl( | ||
| LR"BASH(bash -ec ' | ||
| d=$(mktemp -d) |
There was a problem hiding this comment.
nit: I think this would be a bit easier to read if we just built in the current directory. We can just remove t in scope exit
Summary
/usr/src/linux-headers-$(uname -r)and point/lib/modules/$(uname -r)/buildto them/usr/lib/linux-tools/$(uname -r), add it to the defaultPATH, and configurePERF_EXEC_PATH/usr/bin/perfwith the matching bundled binary without replacing the distro fileFollow-up to #41267.
Validation
cmake --build . -- -mbin\x64\debug\test.bat /name:*KernelArtifacts*mkdocs build -f doc\mkdocs.yml.\FormatSource.ps1