From 75d10c2f90cf3409ea72b3f95767a9a7db573d43 Mon Sep 17 00:00:00 2001 From: vasilito Date: Fri, 19 Jun 2026 00:09:51 +0300 Subject: [PATCH] docs: comprehensive update to upstream-sync known issues Document all kernel compile errors and fixes from V151-V156: - Feature gates (asm_cfg, if_let_guard) - Unsafe blocks (Rust 2024 edition) - Removed Red Bear APIs (SchedPolicy, RUN_QUEUE_COUNT, etc.) - CONTEXT_SWITCH_LOCK missing - new_addrsp_guard field missing - switch.rs must be replaced entirely (EEVDF replaces DWRR) - kcall signature change - ProcSchemeVerb new variants - notify_files type change (Vec -> SmallVec) - RSDP signature change - Cookbook symlink behavior for local forks - m4 platform detection and -fcommon fix Author: vasilito --- local/docs/UPSTREAM-SYNC-PROCEDURE.md | 142 ++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) diff --git a/local/docs/UPSTREAM-SYNC-PROCEDURE.md b/local/docs/UPSTREAM-SYNC-PROCEDURE.md index 3aef6cbfa1..f01106b470 100644 --- a/local/docs/UPSTREAM-SYNC-PROCEDURE.md +++ b/local/docs/UPSTREAM-SYNC-PROCEDURE.md @@ -456,3 +456,145 @@ fail against the synced upstream code. **Fix:** Switched recipe to `path = "../../../local/sources/kernel"` (local fork mode). All patches were already squash-merged into the fork. + +### Kernel: Compile Errors After Upstream Sync (31 errors) + +After the squash-merge, the kernel had 31 compile errors across ~20 files. +These were caused by upstream API evolution interacting with Red Bear code +that survived in non-conflicting regions of the merge. + +#### Feature Gates Required + +Upstream code uses two experimental features that require feature gates: +- `#![feature(asm_cfg)]` — for `#[cfg(target_arch)]` on inline assembly +- `#![feature(if_let_guard)]` — for `if let` guards in match arms + +Both must be added to `src/main.rs`. + +#### Unsafe Blocks Required (Rust 2024 Edition) + +Rust 2024 edition requires explicit `unsafe { }` blocks for unsafe operations +even inside `unsafe fn`. Affected files: +- `src/arch/x86_shared/cpuid.rs` — `__cpuid_count` +- `src/arch/x86_shared/device/tsc.rs` — `__cpuid` +- `src/arch/x86_shared/device/local_apic.rs` — `set_lvt_timer` + +#### Removed Red Bear APIs + +These Red Bear types/constants no longer exist after taking upstream: +- `SchedPolicy` — Red Bear's DWRR scheduler policy enum (upstream uses EEVDF) +- `RUN_QUEUE_COUNT` — Red Bear's per-NUMA run queue count constant +- `get_event_stat()` — Red Bear's event system statistics (upstream uses eventfd) +- `PIPES` — Red Bear's pipe storage (renamed to `HANDLES`) + +Fixes: +- Remove `SchedPolicy` from the `pub use` in `context/mod.rs` +- Define `RUN_QUEUE_COUNT` locally in `percpu.rs` if still needed +- Implement `get_event_stat()` in `event.rs` using the upstream `REGISTRY` static +- Use `HANDLES` instead of `PIPES` in `scheme/pipe.rs` + +#### `CONTEXT_SWITCH_LOCK` Missing + +Upstream added `pub static CONTEXT_SWITCH_LOCK: AtomicBool` to +`src/context/arch/x86_64.rs` but our fork was missing it. Must be added +with the `core::sync::atomic::AtomicBool` import. + +#### `new_addrsp_guard` Field Missing from PercpuBlock + +Upstream added a separate `new_addrsp_guard: Cell>` +field to `PercpuBlock` for storing the addr space read guard during context +switch. Our fork only had `new_addrsp_tmp` (for the `Arc`). +Both fields must exist. + +#### `switch.rs` Must Be Replaced Entirely + +The Red Bear DWRR scheduler in `switch.rs` is fundamentally incompatible with +the upstream EEVDF scheduler data structures. The `RunContextData` changed from +`set: [VecDeque; N]` to `queue: BTreeMap<(vd, rem_slice, ctxt_id), ...>`. + +The entire `switch.rs` must be replaced with the upstream version: +```bash +git show upstream/master:src/context/switch.rs > src/context/switch.rs +``` + +#### `kcall` Trait Method Signature Changed + +Upstream changed `id: usize` to `fds: &[usize]` in the `kcall` trait method. +Update the `ProcScheme` impl to extract the first element: +```rust +fn kcall(&self, fds: &[usize], ...) -> Result { + let id = *fds.first().ok_or(Error::new(EBADF))?; +``` + +#### `ProcSchemeVerb` New Variants + +Upstream added new variants to `ProcSchemeVerb`: `RegsInt`, `RegsFloat`, +`RegsEnv`, `SchedAffinity`, `Start`. The match in `scheme/proc.rs` must +handle them (currently returns `ENOSYS`). + +#### `notify_files` Type Change + +`handle_notify_files()` now expects `UnmapVec` (`SmallVec<[UnmapResult; 16]>`) +instead of `Vec`. Import `UnmapVec` from `context::memory` and use +`UnmapVec::new()` instead of `Vec::new()`. + +#### `Rsdp::get_rsdp` Signature Change + +Upstream changed the parameter from `Option>` to +`Option<*const u8>`. Convert at the call site: +```rust +Rsdp::get_rsdp(already_supplied_rsdp.map(|ptr| ptr.as_ptr() as *const u8)) +``` + +#### Syntax Error in `acpi/madt/arch/x86.rs` + +A `const` statement was accidentally placed inside a `use crate::{...}` block +during the merge. Must be moved outside. + +#### `halt_boot` Scope Issue + +`halt_boot` was defined inside the `impl KernelArgs` block, making it a method +rather than a free function. Must be moved outside the impl block. + +### Cookbook Symlink Behavior for Local Forks + +**Critical:** When a recipe uses `path = "..."` pointing inside +`/local/sources/` or `/local/recipes/`, the cookbook creates a **symlink** +(not a copy) from `recipes//source` → the local fork path. This means: + +1. Build artifacts and `cargo` operations can modify files in the local fork + through the symlink. +2. After each build attempt, verify the fork's git status: + ```bash + cd local/sources/ + git status --short + ``` +3. If the working tree is dirty, reset before rebuilding: + ```bash + git checkout -- . + ``` +4. Always clean both `target/` and `source/` when restarting a kernel build: + ```bash + rm -rf recipes/core/kernel/target recipes/core/kernel/source + cd local/sources/kernel && git checkout -- . + ``` + +### m4: `getlocalename_l-unsafe.c` Platform Detection + +**Problem:** m4's gnulib `getlocalename_l-unsafe.c` has a Redox case guarded +by `HAVE_GETLOCALENAME_L`, which relibc doesn't define. + +**Fix:** Changed the guard from `__redox__ && HAVE_GETLOCALENAME_L` to just +`__redox__` and return `"C"` (Redox only supports the C/POSIX locale). + +### m4: `rpl_realloc` Multiple Definition + +**Problem:** GCC 10+ defaults to `-fno-common`, causing `rpl_realloc` (gnulib +replacement) to be multiply defined across translation units. + +**Fix:** Add `-fcommon` to CFLAGS in the m4 recipe: +```toml +script = """ +DYNAMIC_INIT +export CFLAGS="-fcommon $CFLAGS" +```