8000 Initial MMU support by Ioan-Cristian · Pull Request #4465 · tock/tock · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Initial MMU support #4465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open

Initial MMU support #4465

wants to merge 30 commits into from

Conversation

Ioan-Cristian
Copy link
Contributor
@Ioan-Cristian Ioan-Cristian commented Jun 12, 2025

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 PR is currently blocked by:

This PR should be labeled as blocked until the previous two PRs are merged.

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.
  • Document the purpose of each new file.

Formatting

  • Ran make prepush.

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>
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>
`initialize_process()` took both kernel pointers and userspace pointers
representing the starting memory of the process and its break. However,
all architectures need userspace pointers only to initialize a process.

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>
…ment system

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

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>
Most architectures should not access any memory during context switch.
The sole exception is ARMv*-M architecture which pushes system call
registers on the stack and pops system call return values from the
stack. Since the architecture lacks a MMU, it doesn't distinguish
between kernel virtual pointers and user virtual pointers. However, it
is more logical to pass user virtual pointers, as the architecture
implementation checks if the stack pointer lies within process' virtual
address 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>
@github-actions github-actions bot added risc-v RISC-V architecture component labels Jun 12, 2025
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
component kernel risc-v RISC-V architecture
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0