Methods to Deal with Insufficient Memory Protection Unit (MPU) Regions
20210389988 · 2021-12-16
Inventors
Cpc classification
G06F3/0604
PHYSICS
G06F3/0644
PHYSICS
G06F9/5077
PHYSICS
International classification
Abstract
This invention presents methods to utilize more regions for tasks than the number of slots in a memory protection unit and to efficiently distribute regions between multiple tasks within a partition.
Claims
1. Methods to utilize more regions for tasks than the number of slots in a memory protection unit and to efficiently distribute said regions between multiple tasks within a partition, consisting of: offsetting said memory protection arrays from said memory protection unit such that lower memory protection unit slots are static and the upper memory protection unit slots are active, wherein static means loaded one time during initialization and active means loaded from a task memory protection array whenever said task starts running and where the sum of static and active slots is the number of memory protection array slots; defining regions to satisfy the requirements for code and data in said partition then putting said regions into an array of regions called a partition template where such partition template may have more regions than the number of slots in said memory protection unit; defining child tasks to perform subfunctions for said partition, each said child task requiring a subset of said partition regions for which said memory protection unit has sufficient slots; creating a main partition task, which creates said child tasks; creating said memory protection arrays by using bit masks to select regions from said partition template for all said tasks.
2. The method of claim 1 wherein there is no said static region if said active region utilizes the whole said memory protection unit.
3. The method of claim 1 wherein said memory protection arrays may have auxiliary slots and the number of said slots may vary from task to task.
4. The method of claim 3 wherein a said auxiliary slot may contain an expansion region and wherein a region load function is provided to load said region into a said active slot of said memory protection unit and into said memory protection array, thus allowing said current task to access said expansion region.
5. The method of claim 4 wherein multiple expansion regions are present in said auxiliary slots of said memory protection array and one of said expansion regions is loaded ahead of said task code that requires it, and this process can be repeated for a multiplicity of said expansion regions, as needed, thereby increasing the number regions that said current task can access beyond the number of said memory protection unit slots.
6. The method of claim 5 used for input/output regions, which tend to be small and used only in small sections of code, yet said partition may need to access several said input/output regions at different times.
7. The method of claim 5 wherein said expansion regions used in ptasks make the transition to utasks easier since said utasks usually require less regions.
8. The method of claim 5 wherein the places in said source code where said expansion regions must be loaded into said memory protection unit and said memory protection array can be found from memory manage faults occurring when said task runs.
9. The method of claim 5 wherein said current task may be preempted and will resume with the said expansion region in said memory protection unit because said expansion region was also loaded into said memory protection array of said current task.
10. The method of claim 3 wherein said auxiliary slot may contain a phantom region, which is a subregion of a region in said active slot of said memory protection unit and thus accessible by said current task and said phantom region is shared with a task in another partition which loads said subregion into an active slot in its memory protection array in order to exchange data between said tasks.
11. The method of claim 1 wherein said bit mask has a bit for each region of said partition template, and each time said bit mask is shifted right, if a 1 is shifted out, the corresponding region in said partition template is loaded into the current slot of said memory protection array and each time a 0 is shifted out said template region is skipped and after each said shift, said partition template pointer is incremented and if said memory protection array slot was loaded, its pointer is incremented and if said bit mask becomes 0, remaining said memory protection array slots are loaded with a NULL region.
Description
BRIEF DESCRIPTION OF DRAWINGS
[0021]
[0022]
[0023]
[0024]
[0025]
[0026]
[0027]
DETAILED DESCRIPTION
[0028] The following information describes a simple embodiment of the invention sufficient to explain how it works. The term “application” is understood to mean the software in an embedded device that performs the functions of that device.
[0029]
[0030] If ok, address 102 is sent to Read/Write Memory 108, Read-Only Memory 109, and I/O Device 110 and any other memories or devices connected to address bus 105. Whichever of these devices recognizes the address then receives data from processor 101 via system data bus 107 or sends data to processor 101 via system data bus 107.
[0031]
[0032] It should be apparent, to one skilled in the art, that other embodiments are possible, such as: multiple processors (either multiple cores on the same chip or multiple processors on different chips), multiple MPUs each connecting to the same or to different system buses, multiple system buses, and other types of memory.
[0033]
[0034] For simplicity,
[0035]
[0036] Every task has its own MPA, which governs the regions that it can access. MPU 301 slot 304 is dedicated for the task stack region (every task has its own stack), slot 305 is dedicated for multiple IO regions, and slots 306 to 309 are used for current task regions. The small numbers in MPA 302 slots 315 to 320 are the corresponding MPU 301 slot numbers. This is required by the Cortex v7M MPU and is not generally needed by other MPUs.
[0037] MPA 302 slots 312 thru 314 are auxiliary slots. Slots 312 and 313 contain IO expansion regions. Either IO1 region in slot 312 or IO2 region in slot 313 can be selected 303 and loaded into MPU 301 slot 305 and into MPA 302 slot 316, depending upon which IO region is needed at a particular place in the code of the current task. MPA 302 slot 314 contains a phantom region. It contains region pmsg, which is a subregion of one of the regions in MPU 301 slots 304 to 309. Hence, the current task can access it. This subregion is made available to other partitions as a region that they are allowed to access for the purpose of exchanging data. It is the basis for tunnel partitions discussed in a concurrent application by this author.
[0038] Hence, in this particular example, the current task is able to access three more regions than MPU 301 would normally permit. It should be apparent to one skilled in the art that the foregoing is just one example of regions for a particular task and that other tasks may have different regions that suit their requirements.
[0039]
[0040]
[0041]
[0042]
[0043] For simplicity,
CONCLUSIONS, RAMIFICATIONS, AND SCOPE
[0044] As presented in the foregoing detailed descriptions, an MPU may be divided into static slots and active slots, if it has enough slots. The static slots are loaded during initialization and normally contain common regions and privileged regions used in pmode. The active slots correspond to the lower slots of the MPA from which the MPU is loaded when a new task starts or resumes. Thus the active slots contain regions specific to the current task, which is running. This structure improves performance and is appropriate for MPUs with a large number of slots, such as 16.
[0045] If the MPU has a moderate number of slots, such as 8, not only may there not be enough slots for static regions, there may not be enough slots for all active regions. As a consequence, it may be necessary to create larger regions or to share regions between partitions. Neither of these solutions is attractive because they reduce isolation between partitions and thus reduce system security. Unfortunately, the vast majority of MCUs in use have only 8-slot MPUs and some MCUs have only 4-slot MPUs. Hence, methods to employ more regions than available MPU slots are of great importance to achieve good security for MCU-based systems.
[0046] This invention adds auxiliary slots to a task's MPA. These can contain expansion regions and phantom regions that are specific to each task. Several expansion regions can share a single active MPU slot. When needed, the appropriate expansion region is loaded into the active MPU slot. Where in the code to place these region loads can be determined from Memory Management Faults (MMFs) when the task runs. Hence, neither redesign nor deep understanding of the code are necessary. Phantom regions are subregions of active regions. They are used to share data with other partitions and they do not require an active slot in the MPA of task of origin. This is the foundation for the tunnel portal presented in a concurrent application by this author.
[0047] An additional method of this invention to overcome insufficient MPU slots is to create a single partition template containing all regions needed by the partition code. These regions are based solely upon the code. The resulting template may be much larger than the available number of MPU slots. If so, special-purpose tasks are defined, each to execute a portion of the partition code, such that each task needs no more regions than there are MPU slots for it to use. These tasks are child tasks that are created by the main partition task, which becomes their parent task. A child task cannot do anything that its parent task cannot do, hence it is a proxy for the parent that is designed to reduce the regions needed by the parent.
[0048] Tasks are usually defined to perform certain functions, then writing the code follows. The unique idea here is that the partition code comes first, then the partition template that includes all regions needed by the code, then the tasks are defined to run the code such that the needed regions of each will fit into the MPU.