userspace: introduce coconut-alloc as allocator#927
Draft
n-ramacciotti wants to merge 17 commits into
Draft
Conversation
69d697d to
4a8ed09
Compare
Contributor
Author
|
v2:
|
4a8ed09 to
2a36887
Compare
Contributor
Author
|
v3:
|
2a36887 to
622b9b2
Compare
Contributor
Author
|
v4:
|
joergroedel
reviewed
Jan 12, 2026
joergroedel
left a comment
Member
There was a problem hiding this comment.
Thanks for your contribution, this looks very promising and I am happy to see progress on the user-mode allocator implementation. Left some comments to consider.
Add the wrappers for system calls which change the memory layout of the user-mode task. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Add conversion support for the user-mode representation of memory mapping flags to the kernel representation. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Implement methods to retrieve a reference to the FileHandle or DirectoryHandle the object points to. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Implement the system call to allow user-mode applications to change their memory layout. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Implement the system call to unmap memory mappings from the virtual address space. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
These two methods can be implemented for trait VirtualMapping to support resizing of an existing mapping. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Convert the map_vmm() and unma_vmm() methods to the more generic map/unmap_range() methods which can handle sub-ranges of VMMs as well. Re-implement map/unmap_vmm() to use the more generic methods. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Move the TLB flush logic to a helper function to re-use it at other places. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Add a method to struct VMR to resize an existing mapping. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Support the resizing of VMalloc mappings. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
This is a workaround to use mmap for anonymous mapping. Currently, mmap looks for obj identifier to identify if the mapping is anonymous or not. Anonymous mappings for the moment is based on the fact that id 0 is free, but it is utilized by the console. This commit fix this by changing the identifier to 1 and it will be removed when mmap will be updated. It has been introduced to test the rest of the allocator logic based on mmap. Signed-off-by: Nicola Ramacciotti <niko.ramak@gmail.com>
Add dependency for coconut-alloc crate in the workspace Signed-off-by: Nicola Ramacciotti <niko.ramak@gmail.com>
Introduce a 64 KiB static heap using `AllocBlock` to support dynamic memory allocation in userspace. Initialize the global heap in the `init()` function from `userlib` before calling the `main` function of the crate. Ensure single initialization of the heap by using `OnceRef`. Signed-off-by: Nicola Ramacciotti <niko.ramak@gmail.com>
Implement the `GlobalAlloc` trait by wrapping the lockless `alloc` and `free` operations of `AllocBlock`, which use atomic operations internally. Since those operation return offset from the start of the block, convert them to pointers relative to the heap base. Signed-off-by: Nicola Ramacciotti <niko.ramak@gmail.com>
Implement `layout_from_size()` and `layout_from_ptr()` utilities to construct `Layout. Signed-off-by: Nicola Ramacciotti <niko.ramak@gmail.com>
Disable custom global allocator during normal test execution since the default allocator is sufficient for unit testing To avoid unused warnings in test builds, move `SvsmUserAllocator` implementation behind a configuration flag Add unit tests for layout calculation. Signed-off-by: Nicola Ramacciotti <niko.ramak@gmail.com>
Allocate a Vec to show that the verify that the userspace memory allocator works correctly Signed-off-by: Nicola Ramacciotti <niko.ramak@gmail.com>
622b9b2 to
0b4a6eb
Compare
Contributor
Author
|
v5:
TODO:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces heap allocation support in userspace.
The heap is a single 64KiB static block initialized by
userlibat startup before calling themainfunction. Atomic state operations ensure that only a single initialization can occur.The PR implements the
GlobalAlloctrait by exploitingAllocBlockfrom coconut-alloc, which supports lockless allocations up to 32KiB using atomic operations.This PR is marked as draft as it depends on the changes from:
removes an unstable feature not available in the current toolchain (1.86.0) andadds a new utility function required in this PR#937: this updates rust toolchain to 1.87.0 as required by coconut-allocThese changes were originally included in #913, which also introduced test in userspace svsm, but as suggested, I split them into multiple PRs.
All feedback and suggestions are welcome