Skip to content

Conversation

@ryanbreen
Copy link
Owner

Summary

This PR fixes multiple ARM64 Copy-on-Write implementation issues to achieve complete parity with x86-64. All 6 CoW tests now pass on ARM64.

Fixes Implemented

  • CoW statistics counters: Added to ARM64 page fault handler to track faults, copies, and optimizations
  • TLB flush on TTBR0 switch: Added tlbi vmalle1is in context_switch.rs and syscall_entry.rs - ARM64 requires explicit TLB invalidation unlike x86-64's automatic CR3 behavior
  • Fork stack copy via HHDM: Fixed to use physical addresses through HHDM instead of virtual addresses (TTBR0 still points to parent during copy, causing corruption)
  • cleanup_cow_frames: Implemented for ARM64 to properly decrement reference counts when process exits
  • sbrk check: Fixed in libbreenix to use >= instead of == for page alignment
  • cow_oom_test design: Fixed to enable OOM after fork (fork requires frame allocation for page tables)
  • Exception handler SIGSEGV: Fixed to terminate userspace processes with SIGSEGV on unhandled data aborts instead of hanging

Test Results (ARM64)

Test Result
cow_readonly_test ✅ PASS
cow_signal_test ✅ PASS
cow_cleanup_test ✅ PASS
cow_sole_owner_test ✅ PASS
cow_stress_test ✅ PASS
cow_oom_test ✅ PASS

6/6 tests pass - Full CoW parity achieved.

Files Changed

  • kernel/src/arch_impl/aarch64/context_switch.rs - TLB flush
  • kernel/src/arch_impl/aarch64/exception.rs - CoW stats, SIGSEGV handling
  • kernel/src/arch_impl/aarch64/syscall_entry.rs - TLB flush
  • kernel/src/interrupts.rs - Re-export shared cow_stats module
  • kernel/src/memory/cow_stats.rs - NEW: Shared CoW statistics module
  • kernel/src/memory/layout.rs - Stack address validation fix
  • kernel/src/memory/mod.rs - Add cow_stats module
  • kernel/src/process/manager.rs - HHDM-based fork stack copy
  • kernel/src/process/process.rs - cleanup_cow_frames implementation
  • libs/libbreenix/src/memory.rs - sbrk page alignment fix
  • userspace/tests/cow_oom_test.rs - Test design fix
  • docs/planning/ARM64_TEST_CATALOG.md - NEW: Comprehensive test catalog

🤖 Generated with Claude Code

This commit fixes multiple ARM64 CoW implementation issues to achieve
complete parity with x86-64. All 6 CoW tests now pass on ARM64.

Fixes implemented:
- Add CoW statistics counters to ARM64 page fault handler
- Add TLB flush (tlbi vmalle1is) after TTBR0 switch in context_switch.rs,
  syscall_entry.rs - ARM64 requires explicit TLB invalidation unlike x86-64
- Fix fork stack copy to use HHDM physical addresses instead of virtual
  addresses (TTBR0 still points to parent during copy)
- Implement cleanup_cow_frames for ARM64 to properly decrement reference
  counts when process exits
- Fix sbrk check in libbreenix to use >= instead of == for page alignment
- Fix cow_oom_test to enable OOM after fork (fork requires frame allocation)
- Fix ARM64 exception handler to terminate userspace processes with SIGSEGV
  on unhandled data aborts instead of hanging

Test results (ARM64):
- cow_readonly_test: PASS
- cow_signal_test: PASS
- cow_cleanup_test: PASS
- cow_sole_owner_test: PASS
- cow_stress_test: PASS
- cow_oom_test: PASS

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@ryanbreen ryanbreen merged commit 1e0231d into main Feb 3, 2026
@ryanbreen ryanbreen deleted the feature/arm64-cow-parity branch February 3, 2026 12:09
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.

2 participants