Skip to content

feat(extensions): sysrq-serial-trigger + kernel-debug-tiers (on-device kernel debugging via serial console)#9775

Closed
iav wants to merge 3 commits intomainfrom
feat/sysrq-serial-trigger
Closed

feat(extensions): sysrq-serial-trigger + kernel-debug-tiers (on-device kernel debugging via serial console)#9775
iav wants to merge 3 commits intomainfrom
feat/sysrq-serial-trigger

Conversation

@iav
Copy link
Copy Markdown
Contributor

@iav iav commented May 7, 2026

Description

Two extensions that, together with the kernel patches already merged as PR #9750 (rk3399 8250_dw) and PR #9760 (mvebu-6.18 8250_dw), form a coherent system for on-device kernel debugging through the serial console on headless ARM boards (NAS-style: helios4, helios64, similar).

Each piece is necessary, none is sufficient on its own:

  • kernel-debug-tiers turns on the kernel-side information without which there is nothing to debug — BTF for hung-task tracebacks, printk timestamps and PRINTK_CALLER, lockup/hung-task detection, pstore/ramoops for post-reboot dmesg, KGDB symbol resolution. Three cumulative tiers (KERNEL_DEBUG_TIER=1|2|3, default 1) so the operator picks the cost they're willing to pay; tier 0 is a deliberate no-op.

  • sysrq-serial-trigger turns on the serial console as a debug surface — MAGIC_SYSRQ + MAGIC_SYSRQ_SERIAL_SEQUENCE in kconfig, kernel.sysrq=1 sysctl, and a long enough u-boot BOOTDELAY for the operator to actually catch the prompt. Without this, even a kernel full of debug info can only be examined post-mortem; nothing can be done about a live hang.

  • The 8250_dw driver patches (PR fix(kernel/rockchip64-7.0): restore SysRq-via-BREAK on dw-apb-uart (8250_dw) #9750/fix(kernel/mvebu-6.18): restore SysRq-via-BREAK on dw-apb-uart (8250_dw) #9760, already merged) close the last gap on rk3399 and mvebu: the BREAK condition on a dw-apb-uart goes through dw8250_handle_irq(), which used to swallow LSR.BI without invoking uart_handle_break()handle_sysrq_from_serial(). Before those patches, even a fully configured SysRq-over-serial setup on these SoCs only appeared to work; the operator's BREAK never reached the SysRq dispatcher.

Together these three changes make the well-documented "send BREAK, type the magic sequence, then press a SysRq command" workflow actually functional on rk3399 and mvebu boards, with enough kernel debug info behind it that the resulting tracebacks and KGDB sessions are informative rather than just hex addresses.

Tier guarantees

  • Hard-fail on conflicting BTF preference: KERNEL_BTF=no + KERNEL_DEBUG_TIER>=1 exits early in extension_prepare_config with a helpful message (set KERNEL_BTF=yes/leave unset, or KERNEL_DEBUG_TIER=0).
  • Tier 0 is a real opt-out (extension stays loaded, kernel side off) — useful in shared configs where some boards must keep KERNEL_BTF=no for RAM reasons.
  • sysrq-serial-trigger is independent of the debug tiers; either can be enabled standalone.

Tests performed

End-to-end on helios64 (rockchip64-edge, kernel 7.0.3-rockchip64):

Run Override Expected Result
T1 KERNEL_DEBUG_TIER=1 (default) full kernel build, tier 1 markers + sysrq markers ✓ build OK, kernel 7.0.3-rockchip64, 40m30s
T0 KERNEL_DEBUG_TIER=0 extension loaded, no tier-N kconfig changes
T2 KERNEL_DEBUG_TIER=2 tier 1 + tier 2 (pstore), no tier 3
T3 KERNEL_DEBUG_TIER=3 tier 1 + tier 2 + tier 3 (KGDB)
BTF guard KERNEL_BTF=no (default tier 1) hard-fail in extension_prepare_config ✓ rc=43, exact error message
BTF=no + T0 KERNEL_BTF=no KERNEL_DEBUG_TIER=0 guard skipped, build proceeds

Checklist

Assisted-by: Claude:claude-opus-4.7

Summary by CodeRabbit

  • New Features
    • Kernel debug tier system (levels 0–3) with validated tier selection; progressively enables low-cost diagnostics, persistent pstore/ramoops tracing, and optional remote KGDB/KDB serial debug (attach via kgdboc bootarg).
    • Magic SysRq over serial: enables serial SysRq handling, extends boot console prompt window for operator interaction, and forces sysrq=1 in the final image.

Enable Magic SysRq through the serial console for headless ARM boards
(Helios64, etc.). Mainline ships MAGIC_SYSRQ_SERIAL_SEQUENCE empty,
disabling BREAK-triggered SysRq; this extension fills it with a
deliberate sequence after BREAK so the operator on the serial console
can sync/remount-RO/reboot from any kernel state where interrupts flow.
Also overrides distro kernel.sysrq=176 to 1 (full command set) and
extends u-boot autoboot delay so the prompt is actually catchable.

Pair with the companion `kernel-debug-tiers` extension to make the
tracebacks reachable via SysRq actually informative (BTF, hung-task,
KGDB symbol resolution).

Signed-off-by: Igor Velkov <325961+iav@users.noreply.github.com>
@iav iav requested a review from igorpecovnik as a code owner May 7, 2026 03:08
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 34dcc8dd-10d7-4129-b85e-b90c4b06fed6

📥 Commits

Reviewing files that changed from the base of the PR and between fefa5ec and 1d2eafb.

📒 Files selected for processing (1)
  • extensions/kernel-debug-tiers.sh

Disabled knowledge base sources:

  • Jira integration is disabled

You can enable these sources in your CodeRabbit configuration.


📝 Walkthrough

Walkthrough

Two new Armbian build extension scripts are added: extensions/kernel-debug-tiers.sh introduces configurable cumulative kernel debug tiers (0–3) with validations and tiered kernel config changes; extensions/sysrq-serial-trigger.sh enables Magic SysRq over serial, adjusts U-Boot autoboot timing, and enforces userland kernel.sysrq via an image sysctl.d file.

Changes

Kernel Debug Tiers

Layer / File(s) Summary
Validation & Setup
extensions/kernel-debug-tiers.sh
Adds extension_prepare_config__kernel_debug_tiers() to parse/validate KERNEL_DEBUG_TIER (0–3), treat tier 0 as deliberate kernel no-op, normalize/log KERNEL_BTF, and hard-fail when KERNEL_BTF=no conflicts with KERNEL_DEBUG_TIER>=1.
Tier 1: Lightweight Diagnostics
extensions/kernel-debug-tiers.sh
Adds custom_kernel_config__kernel_debug_tier1() to enable printk timestamps/caller, hung-task/softlockup detection, stack overflow and scheduler stack-end checks when tier≥1; sets DEFAULT_HUNG_TASK_TIMEOUT=120.
Tier 2: Persistent Storage for Crashes
extensions/kernel-debug-tiers.sh
Adds custom_kernel_config__kernel_debug_tier2_pstore() to enable pstore/ramoops-related kernel options when tier≥2 (notes DT/bootargs reservation required to be effective).
Tier 3: KGDB/KDB Serial Support
extensions/kernel-debug-tiers.sh
Adds custom_kernel_config__kernel_debug_tier3_kgdb() to enable KGDB/KDB serial console kconfig options when tier≥3 and sets KDB_DEFAULT_ENABLE=0xFF; relies on kgdboc=<port>,<baud> in bootargs for attachment.

SysRq Serial Trigger

Layer / File(s) Summary
Kernel Configuration
extensions/sysrq-serial-trigger.sh
Adds custom_kernel_config__sysrq_serial_trigger() to set Magic SysRq kernel config flags and populate MAGIC_SYSRQ_SERIAL_SEQUENCE either by modifying .config or updating kernel_config_modifying_hashes.
U-Boot Boot Environment
extensions/sysrq-serial-trigger.sh
Adds post_config_uboot_target__sysrq_serial_uboot_autoboot() to set CONFIG_BOOTDELAY=5 and enable CONFIG_AUTOBOOT_NEVER_TIMEOUT during U-Boot target config to provide a usable prompt window.
Userland Configuration
extensions/sysrq-serial-trigger.sh
Adds post_customize_image__sysrq_serial_trigger_userland() to write ${SDCARD}/etc/sysctl.d/60-armbian-sysrq.conf forcing kernel.sysrq = 1 in the final image.

Sequence Diagram(s)

sequenceDiagram
  participant Builder as Build System
  participant KernelCfg as Kernel .config/Kconfig
  participant UBootCfg as U-Boot config
  participant Image as Target Image (rootfs)
  participant Boot as Bootloader/Runtime

  Builder->>KernelCfg: extension_prepare_config__kernel_debug_tiers() validate tier & BTF
  Builder->>KernelCfg: custom_kernel_config__kernel_debug_tier1/2/3() set kconfig flags
  Builder->>KernelCfg: custom_kernel_config__sysrq_serial_trigger() set Magic SysRq flags
  Builder->>UBootCfg: post_config_uboot_target__sysrq_serial_uboot_autoboot() set bootdelay/autoboot flags
  Builder->>Image: post_customize_image__sysrq_serial_trigger_userland() write sysctl.d (kernel.sysrq=1)
  Boot->>Boot: runtime uses bootargs (kgdboc=...) / DT reservations for pstore
  Boot->>KernelCfg: kernel boots with enabled debug tiers and serial/sysrq support
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A rabbit tweaks kernels, calm and spry,
Tiers of debug reach to the sky—
SysRq hums on the serial line,
U-Boot waits, the logs align,
Hops of insight, tiny and shy. 🐰

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title comprehensively and clearly describes the main changes: two new extensions (sysrq-serial-trigger and kernel-debug-tiers) for on-device kernel debugging via serial console.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/sysrq-serial-trigger

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added 05 Milestone: Second quarter release size/medium PR with more then 50 and less then 250 lines Needs review Seeking for review Framework Framework components labels May 7, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@extensions/kernel-debug-tiers.sh`:
- Around line 88-95: The opts_y list currently includes DEBUG_STACKOVERFLOW
which is x86-only and will be ignored on ARM/ARM64; remove DEBUG_STACKOVERFLOW
from the opts_y array (or wrap its addition in an architecture guard) and
instead add a brief comment near opts_y explaining that ARM/ARM64 uses
VMAP_STACK (symbol VMAP_STACK) for stack overflow protection and that VMAP_STACK
is enabled by default on ARM64 so no DEBUG_STACKOVERFLOW entry is needed; update
any code that assumes DEBUG_STACKOVERFLOW was enabled to rely on VMAP_STACK or
an arch-specific check.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 60785b52-ca37-4579-826a-bbc6f266c158

📥 Commits

Reviewing files that changed from the base of the PR and between 7d91e37 and fefa5ec.

📒 Files selected for processing (2)
  • extensions/kernel-debug-tiers.sh
  • extensions/sysrq-serial-trigger.sh

Comment thread extensions/kernel-debug-tiers.sh
iav added 2 commits May 7, 2026 06:18
Cumulative kernel debug-information tiers for headless boards that need
on-device debugging through the serial console:

  KERNEL_DEBUG_TIER=0    no-op (extension loaded but kernel-side disabled)
  KERNEL_DEBUG_TIER=1    printk timestamps + lockup/hung-task detection
                         (default — cheap, no board prerequisites)
  KERNEL_DEBUG_TIER=2    + pstore/ramoops (needs DT or bootarg reservation)
  KERNEL_DEBUG_TIER=3    + KGDB/KDB over serial (needs kgdboc= bootarg)

By itself the extension does nothing visible at runtime; it bakes enough
information into the kernel image that operator-console facilities like
SysRq tracebacks and KGDB sessions are actually useful instead of streams
of hex addresses. Pair with `sysrq-serial-trigger` (separate extension)
to also enable the operator-control surface itself.

extension_prepare_config validates the tier value, hard-fails with a
helpful message on KERNEL_BTF=no + KERNEL_DEBUG_TIER>=1 (BTF is required
for hung-task tracebacks and KGDB symbol resolution; either set
KERNEL_BTF=yes or KERNEL_DEBUG_TIER=0 to opt out of the kernel side),
and forces KERNEL_BTF=yes for tier>=1 when not explicitly set.

Signed-off-by: Igor Velkov <325961+iav@users.noreply.github.com>
CR: CONFIG_DEBUG_STACKOVERFLOW is implemented for x86/mips/powerpc/etc.
but not for ARM/ARM64. On rk3399 (helios64) and mvebu (helios4) the
extension's target boards, `scripts/config --enable DEBUG_STACKOVERFLOW`
writes the option, but `make olddefconfig` then strips it because the
symbol is not selectable on those architectures. The extension thus
silently does nothing for stack-overflow detection on its primary
targets while creating the impression that the protection is active.

Drop it from tier 1. The remaining tier 1 settings (printk timestamps +
PRINTK_CALLER + DETECT_HUNG_TASK + SOFTLOCKUP_DETECTOR + SCHED_STACK_END_CHECK)
all work on ARM/ARM64.

Signed-off-by: Igor Velkov <325961+iav@users.noreply.github.com>
@iav iav force-pushed the feat/sysrq-serial-trigger branch from fefa5ec to 1d2eafb Compare May 7, 2026 03:18
@iav iav closed this May 7, 2026
@iav iav deleted the feat/sysrq-serial-trigger branch May 7, 2026 03:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

05 Milestone: Second quarter release Framework Framework components Needs review Seeking for review size/medium PR with more then 50 and less then 250 lines

Development

Successfully merging this pull request may close these issues.

1 participant