Skip to content

Expand kernel module guide#374

Merged
jserv merged 1 commit into
masterfrom
refine
Apr 25, 2026
Merged

Expand kernel module guide#374
jserv merged 1 commit into
masterfrom
refine

Conversation

@jserv

@jserv jserv commented Apr 25, 2026

Copy link
Copy Markdown
Contributor
  • Recommended CONFIG options for module development (KASAN, LOCKDEP, DEBUG_ATOMIC_SLEEP, DYNAMIC_DEBUG, DEBUG_INFO, MODULE_FORCE_UNLOAD).
  • printk rate limiting (pr_*_ratelimited, CONFIG_LOG_BUF_SHIFT) and dynamic debug (pr_debug + dyndbg runtime control).
  • Expanded vermagic explanation: what the string encodes, how CONFIG_MODVERSIONS CRC checksums reject ABI-incompatible modules.
  • Canonical goto-based init error-handling pattern with reverse-order cleanup.
  • IS_ERR/PTR_ERR/ERR_PTR convention, distinguishing ERR_PTR-returning APIs (class_create) from NULL-returning ones (kmalloc, proc_create).
  • Module-loading race warning: register last, unregister first.
  • Execution context overview: three kernel entry mechanisms, the "current" macro, and a process/softirq/hardirq capability table.
  • Spinlock variant decision table and same-CPU deadlock scenario, with threaded-IRQ caveat.
  • open/release/flush semantics and private_data lifecycle.
  • sysfs /sys layout overview (devices, bus, class, module, kernel, firmware, power) before the coding example.
  • copy_from_user exception-table mechanism and SMAP/PAN hardware enforcement explaining why raw user-pointer dereference crashes.
  • Four new Common Pitfalls subsections: kernel stack limits, no floating point, buffer pre-initialization for copy_to_user, and double-underscore function conventions.

Makefile: fix blank-line rendering in HTML code blocks. make4ht emits N\n for blank source lines; the newline trapped inside the display:inline-block span collapses to zero height. Move the newline outside the span so

 renders it as a visible line break.  Tested against 1038 affected lines in the deployed HTML; zero remain after the fix.


Summary by cubic

Expands the kernel module guide with practical debugging, ABI, and concurrency guidance to prevent common bugs, and fixes HTML rendering for blank lines in code blocks.
This improves developer workflows and makes the guide safer and easier to follow.

  • New Features

    • Dev and logging: recommended CONFIGs, rate-limited printk, dynamic debug.
    • ABI and init: version magic and CONFIG_MODVERSIONS, goto-based cleanup, ERR_PTR/IS_ERR patterns, register-last/unregister-first.
    • Concurrency and locking: process/softirq/hardirq rules, current meaning, spinlock variant guidance with same-CPU deadlock note, file open/release/flush and private_data.
    • Interfaces and safety: sysfs map, copy_from_user + SMAP/PAN, pitfalls (small stack, no FP, zero buffers before copy_to_user, double-underscore APIs).
  • Bug Fixes

    • Fix blank-line rendering in HTML code blocks from make4ht by relocating trapped newlines so <pre> shows them.

Written for commit 1d15f7100b82a13d18dee7f92f1ad0f5aa11def3. Summary will update on new commits.

- Recommended CONFIG options for module development (KASAN, LOCKDEP,
  DEBUG_ATOMIC_SLEEP, DYNAMIC_DEBUG, DEBUG_INFO, MODULE_FORCE_UNLOAD).
- printk rate limiting (pr_*_ratelimited, CONFIG_LOG_BUF_SHIFT) and
  dynamic debug (pr_debug + dyndbg runtime control).
- Expanded vermagic explanation: what the string encodes, how
  CONFIG_MODVERSIONS CRC checksums reject ABI-incompatible modules.
- Canonical goto-based init error-handling pattern with reverse-order
  cleanup.
- IS_ERR/PTR_ERR/ERR_PTR convention, distinguishing ERR_PTR-returning
  APIs (class_create) from NULL-returning ones (kmalloc, proc_create).
- Module-loading race warning: register last, unregister first.
- Execution context overview: three kernel entry mechanisms, the
  "current" macro, and a process/softirq/hardirq capability table.
- Spinlock variant decision table and same-CPU deadlock scenario, with
  threaded-IRQ caveat.
- open/release/flush semantics and private_data lifecycle.
- sysfs /sys layout overview (devices, bus, class, module, kernel,
  firmware, power) before the coding example.
- copy_from_user exception-table mechanism and SMAP/PAN hardware
  enforcement explaining why raw user-pointer dereference crashes.
- Four new Common Pitfalls subsections: kernel stack limits, no
  floating point, buffer pre-initialization for copy_to_user, and
  double-underscore function conventions.

Makefile: fix blank-line rendering in HTML code blocks.  make4ht
emits <span class='ecrm-0500'>N\n</span> for blank source lines; the
newline trapped inside the display:inline-block span collapses to
zero height.  Move the newline outside the span so <pre> renders it
as a visible line break.  Tested against 1038 affected lines in the
deployed HTML; zero remain after the fix.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

@jserv jserv merged commit 49e7b9f into master Apr 25, 2026
8 checks passed
@jserv jserv deleted the refine branch April 25, 2026 00: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