Skip to content

ref(vmpu): Standardize vMPU driver #216

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

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft

ref(vmpu): Standardize vMPU driver #216

wants to merge 10 commits into from

Conversation

miguelafsilva5
Copy link
Member

@miguelafsilva5 miguelafsilva5 commented May 22, 2025

PR Description

This PR aims to stantardize the vMPU driver and to the some extend the MPU API. This was needed to support different MPU implementations.
A major goal of this PR is remove the complexity from the MPU driver and move it to the vMPU.

The history of this PR still has to be reviewed.

Current MPU implementation have to be updated to comply with this PR.

@@ -546,7 +587,7 @@ vaddr_t mem_map_cpy(struct addr_space* ass, struct addr_space* asd, vaddr_t vas,
mpr = mpe->region;
spin_unlock(&ass->lock);

if (mem_map(asd, &mpr, true)) {
if (mem_map(asd, &mpr, true, false)) {
Copy link
Member

Choose a reason for hiding this comment

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

Just a note that I think these type of invocations are not easily readable.
It would be best to have some macros (e.g., MPU_ENTRY_LOCKED, MPU_ENTRY_UNLOCKED) and used inplace of the true/false values which add little semantic information

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree with you. However, this false/true might not reflect if the entry will be locked or not. It's just a "guideline" for later functions to decide if the entry is locked or not.

@@ -164,7 +164,7 @@ static void mem_init_boot_regions(void)
.mem_flags = PTE_HYP_FLAGS,
.as_sec = SEC_HYP_IMAGE,
};
mem_map(&cpu()->as, &mpr, true, true);
mem_map(&cpu()->as, &mpr, false, true);
Copy link
Member

@DavidMCerdeira DavidMCerdeira Jun 14, 2025

Choose a reason for hiding this comment

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

Similarly to a comment I made before, It would be best to have some macros (e.g., MPU_BROADCAST, MPU_NO_BROADCAST) used in place of the true/false values which add little semantic information

Copy link
Member Author

Choose a reason for hiding this comment

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

Similar to the locked comment. Later functions decide if the regions need to be broadcast or not.

@miguelafsilva5 miguelafsilva5 force-pushed the ref/vmpu branch 7 times, most recently from d1eb470 to 327ac4a Compare June 17, 2025 09:45
josecm and others added 5 commits June 17, 2025 15:42
Signed-off-by: Jose Martins <josemartins90@gmail.com>
Signed-off-by: Jose Martins <josemartins90@gmail.com>
Added an ordered list structure to the vmpu to facilitate the merge
of regions.

Signed-off-by: Daniel Oliveira <drawnpoetry@gmail.com>
Add functionality to lock entries on the vMPU to prevent hypervisor
MPU entries from being removed.

Signed-off-by: Daniel Oliveira <drawnpoetry@gmail.com>
This API simplifies the implementation of vMPU entries
coalescense.
Updating a region requires a broadcast to the other
CPUs on the same address space.
This commit also fixes the install of the VM images
where MPU entries on other cores were not correctly
unmaped.

Signed-off-by: Daniel Oliveira <drawnpoetry@gmail.com>
Signed-off-by: Miguel Silva <miguelafsilva5@gmail.com>
@danielRep danielRep force-pushed the ref/vmpu branch 2 times, most recently from 0c17b42 to 1fa7ca3 Compare June 17, 2025 14:50
@DavidMCerdeira DavidMCerdeira self-requested a review June 17, 2025 14:57
@danielRep danielRep force-pushed the ref/vmpu branch 4 times, most recently from ef8a1ee to 91a5c37 Compare June 17, 2025 15:11
Comment on lines +175 to +184
bool mpu_perms_compatible(unsigned long perms1, unsigned long perms2)
{
bitmap_clear_consecutive(cpu()->arch.profile.mpu.bitmap, 0, mpu_num_entries());
list_init(&cpu()->arch.profile.mpu.order.list);
UNUSED_ARG(perms1);
UNUSED_ARG(perms2);

for (mpid_t mpid = 0; mpid < (mpid_t)mpu_num_entries(); mpid++) {
cpu()->arch.profile.mpu.order.node[mpid].mpid = mpid;
return true;
}
Copy link
Member

Choose a reason for hiding this comment

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

How to check mpu perm compaibility?

@miguelafsilva5 miguelafsilva5 force-pushed the ref/vmpu branch 3 times, most recently from d0026bd to 0a52b3e Compare June 23, 2025 14:35
@DavidMCerdeira DavidMCerdeira self-requested a review June 23, 2025 14:42
danielRep and others added 5 commits June 26, 2025 13:44
This reduces the number of vMPU/MPU entries.

Signed-off-by: Daniel Oliveira <drawnpoetry@gmail.com>
Signed-off-by: Miguel Silva <miguelafsilva5@gmail.com>
To simplify boot code we run with mpu disable until the mem init.

Signed-off-by: Daniel Oliveira <drawnpoetry@gmail.com>
Initally, when mapping and copying, the destination region was being
created with the same size of the original region, instead of the size of
the data being copied

Signed-off-by: Miguel Silva <miguelafsilva5@gmail.com>
Removed the complexity from the MPU driver related to the merge
of regions, which was moved to the vMPU level.
Removed the creation of MPU entries during boot.

Signed-off-by: Miguel Silva <miguelafsilva5@gmail.com>
During the context switch of MPU regions, locked entries are not
disabled.

Signed-off-by: Miguel Silva <miguelafsilva5@gmail.com>
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.

4 participants