-
Notifications
You must be signed in to change notification settings - Fork 40
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 object management #456
Open
cxdong
wants to merge
3
commits into
coconut-svsm:main
Choose a base branch
from
cxdong:obj-code
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+243
−0
Conversation
This file contains 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
The syscalls design philosophy is to provide a unified interface for the user to access system resources, which are represented by object handles. This makes objects a fundamental concept in the COCONUT-SVSM kernel An object represents the type of resource like file, VM, vCPU in the COCONUT-SVSM kernel which can be accessible by the user mode. Introduce an Obj trait to represent such type of resource. The Obj trait can be used to define the common functionalities of the objects. It is defined with the trait bounds of Send and Sync, so the objects implementing Obj trait could be sent to another thread and shared between threads safely. ObjHandle is a unique identifier for an object in the current process. An ObjHandle can be converted to a u32 id which can be used by the user mode to access this object. The passed id from the user mode by the syscalls can be converted to an `ObjHandle`, which can be used to access the object in the COCONUT-SVSM kernel. Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.com>
Freax13
approved these changes
Sep 16, 2024
cxdong
force-pushed
the
obj-code
branch
2 times, most recently
from
September 18, 2024 01:34
b856638
to
3b62a6a
Compare
To facilitate the user mode using the object, the COCONUT-SVSM kernel should: - Manage the object's lifecycle properly. The underlying object should be dropped when the user mode closes the object handle via syscalls or the user mode is terminated without closing. - Prevent one user mode process from misusing the object handle opened by another. But the object handles are shared among the threads within the same process. To achieve the above goals, the opened object should be associated with the process which creates it. The task structure is extended to hold the created objects by a BTreeMap with the ObjHandle as the key and the Arc<dyn Obj> as the value. It is wrapped by an Arc and protected by a RWLock, to make it shared among the threads within the same process. Three functions are introduced for the object management: - obj_add() creates a new ObjHandle by adding the object to the current process. - obj_close() removes and drops the object from the current process. - obj_get() searches in the current process and returns the object if it exists. Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.com>
The object is exposed to the user mode via the object-opening related syscalls, which returns the id of the object created by the COCONUT-SVSM kernel. The user mode can make use this id to access the corresponding object via other syscalls. From the user mode's point of view, an ObjHanle is defined to wrap a u32 which is the value returned by an object-opening syscall. This u32 value can be used as the input for the syscalls to access the corresponding kernel object. The ObjHandle doesn't implement Copy/Clone trait, and the From trait is implemented for a reference to ObjHandle to create a u32. Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.com>
Freax13
approved these changes
Sep 18, 2024
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 is the code implementation for the object management. It includes 3 patches, two patches are for the COCONUT-SVSM kernel, which add the Obj trait, ObjHandle and object management. One patch is for the user mode, which add the equivalent ObjHandle define.
The implementation is made according to the object management design code, which has been reviewed at the PR 4530. Thanks to @Freax13 for the invaluable reviews!