Skip to content

Support MMAP and MUNMAP system calls#945

Draft
joergroedel wants to merge 10 commits into
coconut-svsm:mainfrom
joergroedel:mmap
Draft

Support MMAP and MUNMAP system calls#945
joergroedel wants to merge 10 commits into
coconut-svsm:mainfrom
joergroedel:mmap

Conversation

@joergroedel

Copy link
Copy Markdown
Member

This PR implements the MMAP and MUNMAP system calls and foundations for MRESIZE. The system calls do not have Posix semantics yet. In fact, partial unmaps are not supported. A VMM can only be unmapped as a whole for now.

The foundations for MRESIZE are also implemented, but that support is not finished yet. Therefore this PR is marked as Draft.

Comment thread syscall/src/class0.rs
let obj: u64 = if let Some(fd) = handle {
fd.id().into()
} else {
0u64

@n-ramacciotti n-ramacciotti Jan 21, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

With None (Anonymous mapping) here 0 is assigned and it is later used in kernel/src/syscall/class0.rs:

pub fn sys_mmap(
..
let opt = obj_get(obj_id.into()).ok();
let mmap_addr = if let Some(obj) = opt {
 //map with obj
}else{
 //anonymous mapping
}
..

But obj_id 0 is already used in kernel/src/task/tasks.rs:

fn task_attach_console() {
    let file_handle = stdout_open();
    let obj_handle = ObjHandle::new(0);
    current_task()
        .add_obj_at(file_handle, obj_handle)
        .expect("Failed to attach console");
}

So, sys_mmap finds something when looking for object 0 and it enters the wrong branch.

Workaround for testing with coconut-alloc

Changing obj_id to another value (like 1) makes the mmap work correctly when testing in the userspace allocator PR.

This in syscall/src/console.rs should be changed as well:

static CONSOLE_HANDLE: FsObjHandle = FsObjHandle::new(ObjHandle::new(0));

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>
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.

2 participants