Skip to content

Revamped memory management system#10

Draft
Ioan-Cristian wants to merge 168 commits into
x86-abifrom
mmu
Draft

Revamped memory management system#10
Ioan-Cristian wants to merge 168 commits into
x86-abifrom
mmu

Conversation

@Ioan-Cristian

@Ioan-Cristian Ioan-Cristian commented Jun 5, 2025

Copy link
Copy Markdown

Pull Request Overview

This pull request revamps the memory management system completely. The goals of the new memory management are:

  1. Make Tock MMU-capable
  2. Preserve compatibility with MPU architectures
  3. Improve memory safety through abstractions types
  4. Extract any non-architecture specific logic from arch crates to the kernel crate
  5. Same kernel runs on different architectures: MMU-capable, MPU-capable or without memory protection
  6. No overhead for MPU architectures
  7. Configurable memory granule
  8. No changes required for chips and capsule crates.

Testing Strategy

This pull request was tested by running libtock-rs applications on Raspberry Pi Pico, QEMU RISC-V 32-bit and QEMU x86.

TODO or Help Wanted

This pull request still needs to clarify the following points:

  • The current implementation supports only two regions for each process: PROG and RAM. This breaks IPC support (unusued in libtock-rs). A future patch will address this issue.
  • ARMv*-M architectures have limited capabilities due to hardware restrictions: if the region is not a power a two, then only the greatest power of two smaller than the region size is covered, and only if the start of the region is properly aligned. A better algorithm that makes use of subregions could soft the size restriction.
  • Broken process restart. ProcessStandard::create() needs to be refactored in several functions that can be reused by ProcessStandard::reset().
  • Currently, there is some overhead for MPU architectures:
    • ASIDs are useless. They could be simply be (). Impossible to implement since the kernel needs &dyn Process, which in turn means that Process needs to be object-safe.
    • Userspace virtual pointer -> kernel virtual pointer is still performed on allows. This could be a no-op.
  • The granule is currently hard-coded as a 4KiB page. Impossible to make it generic since the kernel needs dyn Process, which in turn means that Process needs to be object-safe.
  • Kernel address space should be mapped at higher addresses on MMU-capable architectures to allow the entire low virtual address space to processes. This feature is architecture dependent. A solution to cover both MPU-capable and MMU-capable architectures needs to be found.

Documentation Updated

  • Add documentation comments on each public method.

Formatting

  • Ran make prepush.

bradjc and others added 30 commits May 21, 2025 12:57
This allows the checker to try multiple keys when verifying a signature.
This generalizes setting the sig verification key from just once at init
to being able to set dynamically, allowing for multiple keys to be used
with signature verification.
This module provides the signature verification but can hold multiple
keys and supports switching between them.
Enable the test ecdsa sig check to support switching between keys.
There are now two signature keys that can be used to verify app
signatures. I've checked that I can install apps signed with both keys
and they both run.
This means the implementor isn't required to hold the slice that could
contain a private key.
Not sure why that was there.
If a caller selects a key that is already active just set that key
again. Do not return an error.
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
… array

Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
… loader

Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
…ion with MPUs

Until this commit, the kernel checked whether the virtual address space
of a process intersects with its own virtual address space. This
approach does not work for MPUs where the kernel and processes share the
same "virtual" address space. This commit fixes this issue by adding a
config value which tells the kernel whether a MPU is used. The method
used for checking if the process memory configuration is valid has been
changed to take use of the config value.

Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
bradjc and others added 2 commits June 26, 2025 11:29
kernel: Implement `ProcessArray` to hold an array of `&Process`s with interior mutability
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Architectures don't need process' starting RAM or its break, as they
should never write to process memory directly. The sole exceptions are
ARMv*-M architectures which push and pop data directly on the stack at
the hardware level. However, ARMv*-M chips lack a MMU, so the user
virtual memory address space and the kernel virtual memory address space
are identical. Furthermore, the hardware guarantees that the memory
pointed by [SP; SP + STACK_FRAME] is accessible to user space.

Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Flushing the TLB is an expensive operation. Doing it after each
configured region degrades system performances. The TLB is now flushed
when enabling user protection, which happens once per process switch.

Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Before flushing the TLB, check whether the MMU has been reconfigured.
This eliminates unnecessary flushes.

Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
On some architectures, the minimum ammount of memory required to run a
process may be null. This caused a panic in the kernel during
ProcessStandard::create(). The case is now handled by asking the memory
manager for 1 byte if the architecture specifies a null ammount of
memory.

Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Since the kernel can handle back requests of null memory, revert back to
0 memory.

Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
…rocess

Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
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.

10 participants