Skip to content

printk: port the printk subsystem to Rust - #24

Draft
bherrera wants to merge 6 commits into
linux-rustfrom
codex/gpt-6/feature/printk-port
Draft

bherrera wants to merge 6 commits into
linux-rustfrom
codex/gpt-6/feature/printk-port

Conversation

@bherrera

@bherrera bherrera commented Sep 21, 2026

Copy link
Copy Markdown

Scope

Implement printk in the agreed order in this PR: ring buffer, nbcon, printk_safe, then printk. The ring buffer implementation is now present; the later units remain outstanding.

The user authorized the scoped LKMM/C-access investigation while this PR is developed. Acceptance of that investigation is not certification of the C/Rust boundary. The single-forwarding-call FFI restriction remains binding.

Implemented checkpoint

  • Rust ring buffer algorithm and original C entry points under CONFIG_RUST_KERNEL.
  • C-generated size, alignment and offset assertions, including execution-context metadata.
  • C helpers forwarding atomics, barriers, memcpy/memset/memchr and warning macros.
  • Headers and C callers unchanged; edition 2024 syntax.

Validation

  • Rust UP vmlinux and C/Rust SMP bzImage builds pass.
  • C and Rust printk-ringbuffer KUnit pass with four CPUs, three writers, ten seconds.
  • Differential: ten seeds × 10,000 operations in both metadata layouts; reservation-gap/panic cases also pass in the base layout.
  • DWARF confirms printk_info sizes 88/112 and dev_info offsets 24/44.
  • herdtools7 7.58: three barrier projections return Never; controls without reader barriers admit the forbidden outcomes.
  • Loom non-recycling reopen/publication passes. The original speculative-copy diagnostic remains a failure, not a passing model.
  • Clippy: no remaining ring-buffer warnings; 25 existing kfifo warnings remain.

Published infrastructure evidence is on misttech/linux-rust branch codex/gpt-6/feature/printk-port (diagnostic 818c24e, validation 3edea95).

Not ready to merge

The compiler/FFI argument, full preservation of C comments, unsafe classification audit, cross-architecture validation, and remaining printk units are unfinished. This PR is a draft implementation checkpoint.

Kill criteria: layout not tripped; original direct-copy ordering criterion still fails, with the authorized scoped alternative under investigation; KRef unaffected.

Record a pending exception for investigating the printk ringbuffer
port after Loom rejects its speculative payload reads. Separate the
state protocol model from the C access and compiler contracts without
claiming that an atomic control validates ordinary C payload accesses.

Keep the proposal inactive until accepted. The existing stop criteria
continue to apply to production ports.

Assisted-by: LLM [Codex]
@bherrera
bherrera force-pushed the codex/gpt-6/feature/printk-port branch from 1a2adae to cf2a8d9 Compare September 21, 2026 02:30
Define merging PR #24 as acceptance of the printk-specific criterion-2
amendment. Preserve the single-forwarding-call FFI restriction and state
that the existing stop criterion remains tripped until acceptance.

Cite the local diagnostic commit and distinguish its minimal race model
from complete ringbuffer certification.

Assisted-by: LLM [Codex]
Record the explicit authorization to implement printk using the scoped
Loom and LKMM validation approach while PR #24 is under development.
Keep certification separate from permission to investigate, and link
the now-published diagnostic and validation evidence.

Assisted-by: LLM [Codex]
Replace the ring buffer algorithm under CONFIG_RUST_KERNEL while
retaining the C header and caller ABI. Generate layout assertions from
the active C configuration, including execution-context metadata.

Keep reservation and recycling decisions in Rust. Forward shared data
accesses, atomics and barriers through C primitives without retaining
the C algorithm behind the boundary.

This is an implementation checkpoint for the printk series. Sequential
differential traces, two metadata layouts, C/Rust SMP KUnit runs and
three LKMM barrier projections pass. The full compiler-boundary argument,
source-comment audit and unsafe classification remain under review.

Assisted-by: LLM [Codex]
@bherrera
bherrera marked this pull request as draft September 21, 2026 12:22
@bherrera bherrera changed the title docs: propose LKMM validation for printk payload accesses printk: port the printk subsystem to Rust Sep 21, 2026
Keep speculative scalar reads inside C READ_ONCE helpers before descriptor validation. This avoids turning ordinary racing memcpy results into Rust scalar values while preserving the ring algorithm and C caller ABI.

Test: printk ringbuffer differential harness, ten seeds and both metadata layouts.
Test: SMP Rust kernel build with printk KUnit configuration.
Assisted-by: LLM [Codex]
Emit the packed flags and level byte offset plus execution-context offsets from the active C layout. Use the generated values in the Rust mirror instead of deriving offsets from neighboring fields.

Test: Rust main crate builds with execution-context metadata enabled.
Assisted-by: LLM [Codex]
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