Skip to content

fix: kernel tracing works without CONFIG_CONSTRUCTORS (module notifier) (1.7.4)#40

Merged
Jo5ta merged 2 commits into
mainfrom
fix/kernel-register-via-notifier
Jul 11, 2026
Merged

fix: kernel tracing works without CONFIG_CONSTRUCTORS (module notifier) (1.7.4)#40
Jo5ta merged 2 commits into
mainfrom
fix/kernel-register-via-notifier

Conversation

@Jo5ta

@Jo5ta Jo5ta commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

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_CONSTRUCTORS is 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 with invalid in_file_offset(0). Tracing silently does nothing. Our QEMU test only passed because it explicitly enabled CONFIG_CONSTRUCTORS.

Fix: the clltk kernel module now also registers a module notifier (register_module_notifier) and does the registration on MODULE_STATE_COMING / de-registration on MODULE_STATE_GOING. Notifiers run on any kernel and need no cooperation from the traced module. The constructor path is kept for CONFIG_CONSTRUCTORS kernels; registration/de-registration are idempotent, so the two paths agree.

Verified in QEMU on a kernel built with CONFIG_CONSTRUCTORS disabled (confirmed absent in the config): 5 trace files created, zero invalid in_file_offset errors — 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_CONSTRUCTORS kernel) is idempotent by construction; the constructor code itself is unchanged from what already passed the QEMU test.

Jo5ta added 2 commits July 11, 2026 17:09
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>
@Jo5ta Jo5ta merged commit e869a9e into main Jul 11, 2026
11 checks passed
@Jo5ta Jo5ta deleted the fix/kernel-register-via-notifier branch July 11, 2026 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant