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

Implement object management #456

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

cxdong
Copy link
Contributor

@cxdong cxdong commented Sep 14, 2024

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!

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>
kernel/src/syscall/obj.rs Outdated Show resolved Hide resolved
@cxdong cxdong force-pushed the obj-code branch 2 times, most recently from b856638 to 3b62a6a Compare September 18, 2024 01:34
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>
kernel/src/syscall/obj.rs Outdated Show resolved Hide resolved
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