Skip to content

Loader MMU Cleanups (AArch64)#482

Merged
Ivan-Velickovic merged 7 commits intoseL4:mainfrom
au-ts:julia/loader-mmu
Apr 29, 2026
Merged

Loader MMU Cleanups (AArch64)#482
Ivan-Velickovic merged 7 commits intoseL4:mainfrom
au-ts:julia/loader-mmu

Conversation

@midnightveil
Copy link
Copy Markdown
Contributor

This is a series of cleanups, except for one commit:

We were previously setting the MemAttr to the Stage 1 AttrIndex values from MAIR_EL1, but since we boot in hyp/stage 2 we were using the reserved 0b100 value (which is constrained unpredictable to behave as one of the other values).

Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
Copy link
Copy Markdown

@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 think comment "loader: cleanup, pte functions return [u8]" makes things worse, not better. The only reason it needs to be an array is because copy_from_slice is used. This comments spreads that local detail to other code with no gain.

Better solution would be to make boot_lvl* u64 arrays or something instead of this weird byte array stuff.

let pt_index_bits = Self::PAGE_TABLE_INDEX_BITS * (pt_levels - level) as u64;
let idx = (addr >> (pt_index_bits + Self::PAGE_SHIFT)) % 512;
let pt_index_bits = PAGE_TABLE_INDEX_BITS * (pt_levels - level) as u64;
let idx = (addr >> (pt_index_bits + PAGE_SHIFT)) % 512;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Shouldn't this be % PAGE_TABLE_INDEX_BITS?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do you mean (1 << PAGE_TABLE_INDEX_BITS)?

But yes I haven't touched RISC-V much.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yes, that's what I meant.

Comment thread tool/microkit/src/loader.rs Outdated
{
let text_index_lvl1 = Riscv64::pt_index(num_pt_levels, text_addr, 1);
let pt_entry = Riscv64::pte_next(boot_lvl2_pt_elf_addr);
let text_index_lvl1 = riscv64::pt_index(num_pt_levels, text_addr, 1);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm surprised that the differences aren't be abstracted away and that there is so much Arch specific code left.

(This puzzlement also applies to the seL4 kernel code, but no reason to duplicate that approach elsewhere.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is true that a lot of it is duplicated. This is by no means done: I didn't even start cleaning up RISC-V much.

But Riscv64 and Aarch64 has different kernel page tables so some has to be different, and the internal layouts need to be different.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sure, top level is different and low level is different. But that doesn't mean that all the intermediate code can't be shared...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree. I just haven't done it yet.

Comment thread tool/microkit/src/loader.rs
Comment thread tool/microkit/src/loader.rs Outdated
Comment thread tool/microkit/src/loader.rs Outdated
Comment thread tool/microkit/src/loader.rs Outdated
Comment thread tool/microkit/src/loader.rs Outdated
Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
midnightveil and others added 3 commits April 29, 2026 16:38
This cleans up the setting of the attributes, plus a bugfix:

We were previously setting MemAttr == 0b100 from the
MT_NORMAL as was used for Stage 1 (AttrIndex via MAIR),
but this is a reserved value for the Stage2 MemAttr values.

Explicitly handle both stage 1 and stage 2 memattr translations
with an enum.

Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
Signed-off-by: Ivan Velickovic <i.velickovic@unsw.edu.au>
Signed-off-by: Ivan Velickovic <i.velickovic@unsw.edu.au>
@Ivan-Velickovic Ivan-Velickovic merged commit 00275d5 into seL4:main Apr 29, 2026
11 checks passed
@midnightveil midnightveil deleted the julia/loader-mmu branch April 29, 2026 07:06
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.

3 participants