-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expose kernel headers and perf to distributions #41400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ben Hillis (benhillis)
wants to merge
2
commits into
master
Choose a base branch
from
user/benhill/kernel_headers_perf_followup
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3003,6 +3003,100 @@ Error code: Wsl/InstallDistro/WSL_E_DISTRO_NOT_FOUND | |
| ValidateOutput(L"dmesg | grep -iF \"failed to load module 'not-found'\" | wc -l", L"1\n", L"", 0); | ||
| } | ||
|
|
||
| WSL2_TEST_METHOD(KernelArtifacts) | ||
| { | ||
| // The unified kernel artifacts VHD provides the kernel headers and the perf tooling | ||
| // alongside the kernel modules. Headers are mounted at /usr/src/linux-headers-$(uname -r) | ||
| // with /lib/modules/$(uname -r)/build symlinked to that directory; perf is mounted at | ||
| // /usr/lib/linux-tools/$(uname -r) and exposed via $PATH. | ||
|
|
||
| // Headers: the build symlink and a representative uapi header are present. | ||
| VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"test -L /lib/modules/$(uname -r)/build", nullptr, nullptr, nullptr, nullptr), 0u); | ||
| VERIFY_ARE_EQUAL( | ||
| LxsstuLaunchWsl(L"test -s /lib/modules/$(uname -r)/build/include/linux/version.h", nullptr, nullptr, nullptr, nullptr), 0u); | ||
|
|
||
| // Headers are usable: compile and run a tiny program that includes recent uapi headers. The | ||
| // identifiers below fail to compile if the headers are missing or too old (BPF_PROG_TYPE_NETFILTER | ||
| // added in 6.4, IORING_OP_FUTEX_WAKE added in 6.7). Their numeric values are not a stable API | ||
| // contract, so the program only checks that <linux/version.h> matches the running kernel. | ||
| VERIFY_ARE_EQUAL( | ||
| LxsstuLaunchWsl( | ||
| LR"BASH(bash -ec ' | ||
| d=$(mktemp -d) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I think this would be a bit easier to read if we just built in the current directory. We can just remove |
||
| trap "rm -rf $d" EXIT | ||
| cat > "$d/t.c" <<EOF | ||
| #include <stdio.h> | ||
| #include <linux/version.h> | ||
| #include <linux/bpf.h> | ||
| #include <linux/io_uring.h> | ||
| int main(void){ | ||
| (void)BPF_PROG_TYPE_NETFILTER; | ||
| (void)IORING_OP_FUTEX_WAKE; | ||
| printf("%u.%u.%u\n", | ||
| LINUX_VERSION_MAJOR, LINUX_VERSION_PATCHLEVEL, LINUX_VERSION_SUBLEVEL); | ||
| return 0; | ||
| } | ||
| EOF | ||
| cc -isystem /lib/modules/$(uname -r)/build/include -o "$d/t" "$d/t.c" | ||
| v=$("$d/t") | ||
| case "$(uname -r)" in "$v"*) exit 0 ;; *) exit 8 ;; esac | ||
| ')BASH", | ||
| nullptr, | ||
| nullptr, | ||
| nullptr, | ||
| nullptr), | ||
| 0u); | ||
|
|
||
| // perf: leave no trace in the distro's file system and make the versioned binary reachable | ||
| // via $PATH, with PERF_EXEC_PATH pointing at its helper scripts. | ||
| // | ||
| // N.B. The test distro does not ship perf, so nothing should be created at /usr/bin/perf. | ||
| VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"test -x /usr/lib/linux-tools/$(uname -r)/bin/perf", nullptr, nullptr, nullptr, nullptr), 0u); | ||
| VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"test ! -e /usr/bin/perf", nullptr, nullptr, nullptr, nullptr), 0u); | ||
| VERIFY_ARE_EQUAL( | ||
| LxsstuLaunchWsl(L"test \"$(command -v perf)\" = \"/usr/lib/linux-tools/$(uname -r)/bin/perf\"", nullptr, nullptr, nullptr, nullptr), 0u); | ||
| VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"perf --version", nullptr, nullptr, nullptr, nullptr), 0u); | ||
| VERIFY_ARE_EQUAL( | ||
| LxsstuLaunchWsl(L"test \"$(perf --exec-path)\" = \"/usr/lib/linux-tools/$(uname -r)/libexec/perf-core\"", nullptr, nullptr, nullptr, nullptr), | ||
| 0u); | ||
|
|
||
| // Stale distro-provided artifacts are replaced or hidden after the VM restarts. A distro | ||
| // provided perf is shadowed by the binary matching the running kernel. | ||
| // | ||
| // N.B. The cleanup is registered before the distro's file system is modified so that a | ||
| // failure can't leave a perf binary or a broken build symlink behind, which would | ||
| // break subsequent runs. | ||
| auto cleanup = wil::scope_exit_log(WI_DIAGNOSTICS_INFO, [&]() { | ||
| LxsstuLaunchWsl( | ||
| L"umount /usr/bin/distro-perf 2>/dev/null; rm -f /usr/bin/perf /usr/bin/distro-perf; ln -snf" | ||
| L" /usr/src/linux-headers-$(uname -r) /lib/modules/$(uname -r)/build", | ||
| nullptr, | ||
| nullptr, | ||
| nullptr, | ||
| nullptr); | ||
| }); | ||
|
|
||
| VERIFY_ARE_EQUAL( | ||
| LxsstuLaunchWsl( | ||
| L"rm /lib/modules/$(uname -r)/build && ln -s /tmp /lib/modules/$(uname -r)/build && printf old-perf >" | ||
| L" /usr/bin/distro-perf && ln -s distro-perf /usr/bin/perf", | ||
| nullptr, | ||
| nullptr, | ||
| nullptr, | ||
| nullptr), | ||
| 0u); | ||
| VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"--shutdown"), 0u); | ||
| VERIFY_ARE_EQUAL( | ||
| LxsstuLaunchWsl(L"test \"$(readlink /lib/modules/$(uname -r)/build)\" = \"/usr/src/linux-headers-$(uname -r)\"", nullptr, nullptr, nullptr, nullptr), | ||
| 0u); | ||
| VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"test \"$(readlink /usr/bin/perf)\" = \"distro-perf\"", nullptr, nullptr, nullptr, nullptr), 0u); | ||
| VERIFY_ARE_EQUAL( | ||
| LxsstuLaunchWsl( | ||
| L"test \"$(stat -Lc %d:%i /usr/bin/perf)\" = \"$(stat -Lc %d:%i /usr/lib/linux-tools/$(uname -r)/bin/perf)\"", nullptr, nullptr, nullptr, nullptr), | ||
| 0u); | ||
| VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"/usr/bin/perf --version", nullptr, nullptr, nullptr, nullptr), 0u); | ||
| } | ||
|
|
||
| WSL2_TEST_METHOD(CrashCollection) | ||
| { | ||
| const auto folder = std::filesystem::absolute(L"test-crash-dumps"); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.