name: Non-Obvious Kernel Design Guidelines description: Critical design decisions from kernel.pdf §5,6,9 that are easy to get wrong type: project


Context Switch vs. Mode Switch (§5.1)

These are completely different:

There should be exactly one code path for context switching. Multiple context-switch code paths indicate multiple conflicting partial understandings and typically mean multiple bugs.

When a thread is suspended in kernel mode (e.g., blocked on a lock), the context switch brings it back to where it was in kernel mode - not to user space.

Locking Design (§9.1.2)

Scheduler (§5.2)

VM and Physical Memory (§2.5, §9.5)

ELF Loading (§7.2)

System Call Validation (§6.2)

Thread Exit / Resource Cleanup (§9.3)

Simics Debugging Integration (§10.6)

For source-level user-space debugging to work:

  1. Enable paging before loading any user programs.
  2. Call sim_reg_process(pd_addr, execname) when loading a new program (or sim_reg_child() for fork).
  3. Call set_cr3() when switching address spaces (Simics auto-switches symbol tables).
  4. Call sim_unreg_process() when a task exits.

Why: These are the non-obvious architectural decisions that kernel.pdf marks as important and that past student kernels commonly got wrong.

How to apply: When reviewing or suggesting implementation strategies for these areas, check against these guidelines.

Table of Content