Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Kswin01
Copy link
Contributor

@Kswin01 Kswin01 commented Oct 20, 2025

This is continuing the work as outlined in PR #967. The original branch has been rebased, and merge issues resolved related to the aarch64 page tables refactor.

Test with: seL4/sel4test#148

@midnightveil midnightveil added hw-test sel4test hardware builds + runs for this PR and removed hw-test sel4test hardware builds + runs for this PR labels Oct 20, 2025
Copy link
Contributor

@Indanz Indanz left a comment

Choose a reason for hiding this comment

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

I'm not convinced that we need is_remap and think it should be enough to check the page table entry we want to update for an existing valid mapping. Removing is_remap would reduce the diff a fair bit. The whole point of this is to prevent remapping, so when would is_remap be true and allowed?

Conceptually, all that is needed to prevent overmapping is one extra check on the destination PTE to see if the slot is free or already used.

@lsf37 lsf37 added the verification Needs formal verification input/change, or is motivated by verification label Oct 20, 2025
@lsf37
Copy link
Member

lsf37 commented Oct 20, 2025

This still needs at least a TSC discussion if not an RFC. It breaks the API for systems that currently use overmapping.

Just because the RISC-V implementation follows the manual does not mean that the manual was correct. The ARM and x86 implementations both predate RISC-V and we have fixed so many misunderstandings in both the RISC-V implementation and in the manual over the years that it is absolutely open what the actual intention should be. Currently, it's just inconsistent and we should consciously decide what we want.

There is also still the question of whether anything should be done at all to the code. The manual can just state what the correct behaviour is for each architecture. There is no actual requirement for them to be the same even if consistency is generally preferable -- the question is who is going to come up with the funding for the verification of this change, it's too large to just do on the side.

@Kswin01
Copy link
Contributor Author

Kswin01 commented Oct 21, 2025

This still needs at least a TSC discussion if not an RFC. It breaks the API for systems that currently use overmapping.

I'm in the process of writing an RFC up for this change, and will make a PR to the rfc repo for that soon.

I'm not convinced that we need is_remap

I agree, I removed that on aarch64. The is_remap is a remnant of the original PR that this is based on, and I'll remove this for other platforms. Nevermind, is_remap seems to be necessary on other platforms due to the the structure of creating mappings (having different functions for different size pages).

The whole point of this is to prevent remapping, so when would is_remap be true and allowed?

My understanding of remap is that it essentially allows a permissions update, so if the supplied frame cap is mapped into the current address space, and doesn't exist in a different mapping within it, then we allow a remap of it (with potentially new permissions). This PR prevents overmapping, which is when we are attempting to over-write an existing mapping with an unmapped frame. So if re-map is true, then the check for over-mapping should be ignored (I believe that was the original intention behind Alwin's original PR).

Copy link
Contributor

@Indanz Indanz left a comment

Choose a reason for hiding this comment

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

So really, the changes can be limited to just an extra check per mapping invocation that checks the info in the current page table entry for presence and current physical address. It's just unfortunate that on some archs this requires a check per page type.

#ifndef CONFIG_ARM_HYPERVISOR_SUPPORT
if (pte_ptr_get_pteType(ret.pte_entries.base) == pte_pte_large) {
#else
if (pte_ptr_get_pteType(ret.pte_entries.base) == pte_pte_small) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is this missing && pte_pte_small_ptr_get_contiguous_hint(ret.pte_entries.base)))?

Comment on lines +1612 to +1615
if (!is_remap) {
userError("Virtual address (0x%"SEL4_PRIx_word") already mapped", vaddr);
current_syscall_error.type = seL4_DeleteFirst;
ret.status = EXCEPTION_SYSCALL_ERROR;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is repeated so often, what about putting it in a separate function?

Comment on lines +2321 to +2324
frame_asid = generic_frame_cap_get_capFMappedASID(cap);

if (generic_frame_cap_get_capFIsMapped(cap)) {
if (generic_frame_cap_get_capFMappedASID(cap) != asid) {
if (frame_asid != asid) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps nicer, but you're not re-using frame_asid, so this change is unnecessary.

return EXCEPTION_SYSCALL_ERROR;
}

is_remap = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

You only need to set this once at the start of the if (generic_frame_cap_get_capFIsMapped(cap)) block.

Comment on lines -1571 to +1576
} else if (cap_frame_cap_get_capFMappedAddress(cap) != vaddr) {
}

/* The invoked frame cap is already mapped to a different address in this vspace */
if (cap_frame_cap_get_capFMappedAddress(cap) != vaddr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

No actual logical change here, just looks like it because the comment was wedged in.


exception_t decodeX86ModeMapPage(word_t label, vm_page_size_t page_size, cte_t *cte, cap_t cap,
vspace_root_t *vroot, vptr_t vaddr, paddr_t paddr, vm_rights_t vm_rights, vm_attributes_t vm_attr)
vspace_root_t *vroot, vptr_t vaddr, paddr_t paddr, vm_rights_t vm_rights, vm_attributes_t vm_attr, asid_t frame_asid)
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't that supposed to be an is_remap? Where did frame_asid come from?

static create_mapping_pdpte_return_t createSafeMappingEntries_PDPTE(paddr_t base, word_t vaddr, vm_rights_t vmRights,
vm_attributes_t attr,
vspace_root_t *vspace)
vspace_root_t *vspace, asid_t frame_asid)
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be actually is_remap, see other comment.


/* Check that we are not overwriting an existing mapping */
if (pdpte_ptr_get_page_size(ret.pdptSlot) == pdpte_pdpte_1g) {
if (pdpte_pdpte_1g_ptr_get_present(ret.pdptSlot) && frame_asid == asidInvalid) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably:

Suggested change
if (pdpte_pdpte_1g_ptr_get_present(ret.pdptSlot) && frame_asid == asidInvalid) {
if (pdpte_pdpte_1g_ptr_get_present(ret.pdptSlot) && !is_remap) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

verification Needs formal verification input/change, or is motivated by verification

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants