Skip to content
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

Refactor the kernel's mm module #145

Merged
merged 7 commits into from
Dec 2, 2023
Merged

Refactor the kernel's mm module #145

merged 7 commits into from
Dec 2, 2023

Conversation

n1tram1
Copy link
Collaborator

@n1tram1 n1tram1 commented Oct 14, 2023

I was feeling like the mm module was a hot mess ready to blow our legs off.

Now that we only map the memory we need as r/w, I hope we will catch bugs earlier (if we create some).
I also prefer those interfaces, and having the PMM thread-safe is a nice step forward.

I should have cleaned up all the weird debug stuff I had left laying around.

In doing so, we were overating over one page too many.
Instead iterate over an exlusive range.
We have to assume PAGE_SIZE from the HAL to be a baked in constant at
compile-time.
Similar to a PAGE_SIZE define in a C project.
Don't pass it because it won't (read *must not*) change at run-time.
@n1tram1 n1tram1 force-pushed the refactor/kernel-mm-module branch from 5632e1a to 2835844 Compare October 14, 2023 14:49
@n1tram1
Copy link
Collaborator Author

n1tram1 commented Oct 14, 2023

Hum, looks like I did not fix riscv alongside aarch64...

Copy link
Collaborator

@Skallwar Skallwar left a comment

Choose a reason for hiding this comment

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

Nice work

I wonder if we should take the time to add a interrupt handler for catching bad memory access since we should be able to catch them now.

hal_core/src/mm.rs Show resolved Hide resolved
hal_core/src/mm.rs Outdated Show resolved Hide resolved
hal_core/src/mm.rs Outdated Show resolved Hide resolved
kernel/src/lib.rs Outdated Show resolved Hide resolved
@@ -97,12 +97,14 @@ fn test_timer_interrupt() -> TestResult {
fn test_pagetable_remap() -> TestResult {
info!("Testing the remapping capabilities of our pagetable...");

let page_src = alloc_pages(1).unwrap();
let page_src = globals::PHYSICAL_MEMORY_MANAGER.alloc(1).unwrap();
let page_src = unsafe { slice::from_raw_parts_mut(page_src as *mut u8, PAGE_SIZE) };
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we should add a wrapper for that because we do this casting in a lot of different places

})?;
let pt = hal_core::mm::prefill_pagetable::<PageTable>(r, rw, rwx, pre_allocated, allocator)?;

// TODO: put into into the hal_core::Error
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do the todo now or later?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oneday 🙏

hal_aarch64/src/mm/mod.rs Outdated Show resolved Hide resolved
Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

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

note that using &impl PageAllocator is similar to using <P: PageAllocator> and &P. the function will be monomorphized and "templated" for each allocator it is used with. If this becomes a problem it might be worth switching to &dyn PageAllocator instead

hal_core/src/mm.rs Outdated Show resolved Hide resolved
Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

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

woops meant to approve this

Had to change a few interfaces to get around ownership issues.
But now that all DRAM is not mapped as r/w, hopefully we will catch bugs
earlier later on.
PageAllocFn was not very wieldy, the alloc_pages_* (alloc_pages_for_hal
etc...) functions were a mess and it was hard to know what to use when
etc...

Use a trait instead, that way we can still pass an allocator that does
not allocate in cases when we don't want to allocate, and pass the whole
allocator when allocations actually are needed.
That way it is easier to add functionality for when the HALs need more
info from the allocator. Also it is much much easier to manage
ownership&lifetimes this way.
Thanks to the previous patch, it was fairly easy to just make the PMM
thread-safe.
It also makes interfaces a bit nicer imo.
Lastly I did it because it was easy and I felt like it.
@n1tram1 n1tram1 force-pushed the refactor/kernel-mm-module branch from 2835844 to e63a319 Compare November 29, 2023 20:53
@n1tram1 n1tram1 force-pushed the refactor/kernel-mm-module branch from e63a319 to 7e73956 Compare November 29, 2023 20:55
@n1tram1 n1tram1 force-pushed the refactor/kernel-mm-module branch from 9b8b759 to ce3d57e Compare December 1, 2023 17:39
@n1tram1 n1tram1 force-pushed the refactor/kernel-mm-module branch from ce3d57e to 72db5f4 Compare December 2, 2023 00:02
@n1tram1 n1tram1 merged commit 346b9cb into main Dec 2, 2023
7 checks passed
@n1tram1 n1tram1 deleted the refactor/kernel-mm-module branch December 2, 2023 00:09
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