fix: kernel tracing works without CONFIG_CONSTRUCTORS (module notifier) (1.7.4)#40
Merged
Conversation
Kernel tracing registered a module's tracebuffers/tracepoints only from a C constructor injected into that module. The kernel calls module constructors only when CONFIG_CONSTRUCTORS is enabled - off in most production kernels - so there the constructor never ran: the module loaded cleanly but no tracebuffer was registered and every tracepoint failed with invalid in_file_offset(0). It worked in our QEMU test only because that test kernel had CONFIG_CONSTRUCTORS on. The clltk kernel module now also registers a module notifier and does the same registration on MODULE_STATE_COMING / deregistration on MODULE_STATE_GOING for every module, which needs no CONFIG_CONSTRUCTORS and no cooperation from the traced module. The constructor path stays for CONFIG_CONSTRUCTORS kernels; registration and de-registration are idempotent, so the two paths agree. Verified in QEMU on a kernel built with CONFIG_CONSTRUCTORS disabled: 5 trace files created, zero invalid-offset errors. Signed-off-by: Jo5ta <jo5ta@mail.de>
Kernel-module .c files are built by Kbuild, not cmake, so they are not in compile_commands.json. clang-tidy-diff would fall back to defaults and fail on the kernel headers. Exclude kernel_tracing_library from the diff; those sources are covered by the kernel-module build job. Signed-off-by: Jo5ta <jo5ta@mail.de>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes a real portability gap in kernel tracing (1.7.4).
The kernel module registered a traced module's tracebuffers/tracepoints only from a C constructor injected into that module. The kernel calls module constructors only when
CONFIG_CONSTRUCTORSis enabled — and it's off in most production kernels (it's pulled in by gcov/KASAN builds). On those kernels the module loads cleanly but the constructor never runs, so nothing registers and every tracepoint fails withinvalid in_file_offset(0). Tracing silently does nothing. Our QEMU test only passed because it explicitly enabledCONFIG_CONSTRUCTORS.Fix: the clltk kernel module now also registers a module notifier (
register_module_notifier) and does the registration onMODULE_STATE_COMING/ de-registration onMODULE_STATE_GOING. Notifiers run on any kernel and need no cooperation from the traced module. The constructor path is kept forCONFIG_CONSTRUCTORSkernels; registration/de-registration are idempotent, so the two paths agree.Verified in QEMU on a kernel built with
CONFIG_CONSTRUCTORSdisabled (confirmed absent in the config): 5 trace files created, zeroinvalid in_file_offseterrors — i.e. the notifier alone registers everything. The module compile/link check (the CI kernel job) also passes with the notifier.Note: the constructor + notifier both-running case (a
CONFIG_CONSTRUCTORSkernel) is idempotent by construction; the constructor code itself is unchanged from what already passed the QEMU test.