Skip to content

Conversation

@etiaro
Copy link

@etiaro etiaro commented Dec 2, 2025

This commit introduces loader support for full MPU regions reconfiguration on context switch, allowing for more flexibile configuration of memory maps on MPU targets.

Changes include

  • MPU configuration during app command, based on hal_syspage_prog_t structure with program configuration of MPU regions in form of ready-to-copy register values
  • reimplementation of mpu command, showing generated mpu configuration on per-app basis
  • passing all maps at once to hal/mpu module, allowing future map merging to reduce count of used MPU regions

JIRA: RTOS-1149

Description

Motivation and Context

This change enables users to define more memory maps, allowing more flexible configuration and better spatial separation of processes, which is first stage of development of partitioning mechanism.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (refactoring, style fixes, git/CI config, submodule management, no code logic changes)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: (list targets here).

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

@gemini-code-assist
Copy link

Summary of Changes

Hello @etiaro, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant architectural enhancement to the Memory Protection Unit (MPU) management system. By shifting from a global MPU configuration to a per-process model, it enables dynamic and flexible memory mapping for individual applications. This change is crucial for improving spatial separation between processes and forms the foundational stage for developing more robust partitioning mechanisms within the system. The refactoring impacts how MPU regions are allocated, managed, and displayed, providing greater control and visibility over memory access permissions for each running program.

Highlights

  • Per-Process MPU Configuration: Introduces loader support for full MPU region reconfiguration on context switch, enabling more flexible memory map configurations tailored to individual processes on MPU targets.
  • Reimplemented MPU Command: The mpu command has been reimplemented to display MPU configuration on a per-application basis, allowing users to inspect the memory protection settings for specific programs.
  • Unified Map Passing: All memory maps are now passed at once to the hal/mpu module, which paves the way for future optimizations like map merging to reduce the total count of used MPU regions.
  • HAL API Update: The hal_memoryAddMap function has been replaced with hal_getProgData, which now accepts a syspage_prog_t structure to populate program-specific MPU configurations.
  • MPU Module Refactoring: The core MPU logic in hal/armv7m/mpu.c, hal/armv7r/mpu.c, and hal/armv8m/mpu.c has been refactored to operate on a per-program context, moving away from a global MPU state for region allocation and management.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a significant and valuable feature: per-process MPU configuration. The changes are extensive, touching multiple architectures to refactor MPU handling from a global to a per-program basis. The core logic in mpu.c files for ARMv7-M, ARMv7-R, and ARMv8-M has been substantially rewritten to support this new model, and the mpu command has been updated accordingly. My review has identified a few areas for improvement, including a critical missing function for ARMv8-M that would cause build failures, some redundant error logging, a leftover logic bug in syspage.c, and an inconsistency in MPU region invalidation logic. Addressing these points will enhance the robustness and maintainability of this new feature.

@etiaro etiaro force-pushed the etiaro/mpu-partitioning branch from 4813059 to fdefe42 Compare December 3, 2025 09:05
This commit introduces loader support for full MPU regions reconfiguration
on context switch, allowing for more flexibile configuration of memory maps
on MPU targets.

Changes include
* MPU configuration during app command, based on hal_syspage_prog_t structure
  with program configuration of MPU regions in form of ready-to-copy register values
* reimplementation of mpu command, showing generated mpu configuration on per-app basis
* passing all maps at once to hal/mpu module, allowing future map merging to reduce
  count of used MPU regions

JIRA: RTOS-1149
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