-
Notifications
You must be signed in to change notification settings - Fork 41
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
Implement initial userspace support #467
base: main
Are you sure you want to change the base?
Implement initial userspace support #467
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some preliminary review comments.
d860c4a
to
a40bb5b
Compare
Thanks @Freax13 for the valuable comments. I have addressed all the earlier comments. Can you please take a look? |
a40bb5b
to
b58ca0b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have time for a full review right now, I'll do that sometime next week.
Now that #456 has been merged, this PR can be rebased onto |
Sure, will rebase, address your other comments and mark the PR ready to review. |
7493e6f
to
ac443c2
Compare
ac443c2
to
82b9c34
Compare
82b9c34
to
f3d3fd0
Compare
FYI this branch has conflicts with main. You might have to rebase your branch to resolve them. |
Yes, done. |
f3d3fd0
to
97228da
Compare
97228da
to
e051109
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thanks!
Thanks for that work, it is pretty impressive! Although it is hard to review on all levels due to its size:
Can you please split this into smaller PRs which we can merge one at a time? Please start with the system call interface and implementation. This PR can be rebased then on what has already been merged. |
Sure, I can split this into smaller PRs. Would splitting commits into the below PRs be helpful?
|
FYI, we merged SMAP support in #473, this PR will have to be adjusted accordingly. |
Add a new trait, Obj, to ensure all of the object handles follow a common interface. This helps with implementing common syscalls that can be used for different object types. Signed-off-by: Peter Fang <[email protected]>
Rename numbers.rs to def.rs so that this file can be extended in the future to contain more definitions, like MMFlag, syscall error code which are common for both kernel and user. Signed-off-by: Chuanxiao Dong <[email protected]>
The syscall handlers in handlers.rs currently is for class0 so rename the file to class0.rs. The plan is to introduce other syscall handlers files for different classes. Signed-off-by: Chuanxiao Dong <[email protected]>
SYS_HELLO is a test syscall and occupies the syscall number 0, which is for SYS_EXIT according to the spec. Remove the SYS_HELLO. Signed-off-by: Chuanxiao Dong <[email protected]>
Add macro to define 5 raw syscalls, which take different number of input arguement. The syscall ABI follows the published system call spec[1]. To trigger syscall to kernel, int 0x80 is used according to the kernel implementation. The syscall macro is derived from [2]. [1]: https://mail.8bytes.org/pipermail/svsm-devel/2024-June/000334.html [2]: https://gitlab.redox-os.org/redox-os/syscall/-/blob/master/src/arch/x86_64.rs Co-developed-by: Vijay Dhanraj <[email protected]> Signed-off-by: Chuanxiao Dong <[email protected]>
Define the raw error code according to syscall spec, and an enum SysCallError to conver the raw error code to rust style error. Co-developed-by: Vijay Dhanraj <[email protected]> Signed-off-by: Chuanxiao Dong <[email protected]>
Add exit() to be used as SYS_EXIT, which takes one exit code as an input parameter according to the spec. Co-developed-by: Vijay Dhanraj <[email protected]> Signed-off-by: Chuanxiao Dong <[email protected]>
The close syscall is implemented by using the obj_remove, to remove the ObjHandle associated witht the input object id from the current task. Co-developed-by: Vijay Dhanraj <[email protected]> Signed-off-by: Chuanxiao Dong <[email protected]>
Implement Drop for the ObjHandle to close the underlying kernel object when drop the ObjHandle in the user mode. Co-developed-by: Vijay Dhanraj <[email protected]> Signed-off-by: Chuanxiao Dong <[email protected]>
FS_ROOT needs to be initialized early enough for process root directory to take effect when setting up BSP's idle task. Signed-off-by: Peter Fang <[email protected]>
Add find_dir() which looks for a directory entry using a relative path. Signed-off-by: Peter Fang <[email protected]>
Add FsObj which is the primary kernel object used for Class 1 syscalls. This object represents both a file and a directory entry. Also, add as_fs() to the Obj trait that allows for these objects to downcast back to FsObjs. Co-developed-by: Vijay Dhanraj <[email protected]> Signed-off-by: Peter Fang <[email protected]>
Add opendir() which allows a Directory object to be returned. Co-developed-by: Vijay Dhanraj <[email protected]> Signed-off-by: Peter Fang <[email protected]>
Hi @joergroedel as suggested, split this PR and added a PR #502 to introduce the syscall interface implementation. |
e051109
to
338851f
Compare
I meant to say that we now need to execute |
Got it, will add the |
338851f
to
b0c0eb6
Compare
@Freax13 I have updated the PR to use |
Personally, I don't have a problem with large PRs, but @joergroedel might object. From your comment above:
It probably makes sense to add the changes to this PR. |
In addition to ensuring invalid memory access, the UserPtr wrapper around GuestPtr validates the address passed from the userspace to make sure it isn't pointing to kernel memory. Signed-off-by: Vijay Dhanraj <[email protected]>
Implement the syscall handlers for SYS_OPENDIR and SYS_READDIR based on the ABI spec. SYS_OPENDIR creates an FsObj representing a directory entry. Co-developed-by: Vijay Dhanraj <[email protected]> Signed-off-by: Peter Fang <[email protected]>
Implement the OPENDIR and READDIR syscall interface in user space. Co-developed-by: Vijay Dhanraj <[email protected]> Signed-off-by: Peter Fang <[email protected]>
If the user process is still running after scheduling, return its TID. Else, indicate that it's already terminated through TaskError. Co-developed-by: Vijay Dhanraj <[email protected]> Signed-off-by: Peter Fang <[email protected]>
Implement the syscall handler for SYS_EXEC. This commit also provides the ability to specify a new root directory for the process. This is done because EXEC allows the parent process to specify the root directory of the new process. New threads automatically inherits its parent's root directory. Co-developed-by: Vijay Dhanraj <[email protected]> Signed-off-by: Peter Fang <[email protected]>
Implement the EXEC syscall interface in user space. Co-developed-by: Vijay Dhanraj <[email protected]> Signed-off-by: Peter Fang <[email protected]>
Add the initial version of init. Currently it only does exec() on a dummy file. This is addressed in the future commits. Introduced "make user" to compile the init process. Co-developed-by: Vijay Dhanraj <[email protected]> Signed-off-by: Peter Fang <[email protected]>
Use opendir() and readdir() for dm discovery. Currently, it naively runs the first file discovered under /bin. Co-developed-by: Vijay Dhanraj <[email protected]> Signed-off-by: Peter Fang <[email protected]>
The device model is a user mode program which manages VM's life cycles and handles various vmexits events. The initial version just calls exit() syscall without doing anything else. As this is a user mode program, not sure what is the preferred way to put this project, just put it as a sub folder in coconut-svsm and in the workspace. If in the workspace is not preferred, this can be changed in the future. Co-developed-by: Vijay Dhanraj <[email protected]> Signed-off-by: Chuanxiao Dong <[email protected]>
b0c0eb6
to
c081cf6
Compare
This is a draft PR that adds basic syscall support like exit, close, opendir, readdir and exec as well as init task and dm implementation. The purpose of this PR is to get feedback from the community and ensure the design aligns with principles of user-mode support described in https://github.com/coconut-svsm/svsm/blob/main/Documentation/docs/developer/DEVELOPMENT-PLAN.md as well syscall ABIs https://mail.8bytes.org/pipermail/svsm-devel/2024-June/000334.html.
PS: The changes are built on top of #456.