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

Commits on Sep 14, 2024

  1. kernel/syscall/obj: Add Obj trait and ObjHandle

    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>
    cxdong committed Sep 14, 2024
    Configuration menu
    Copy the full SHA
    b5ffb37 View commit details
    Browse the repository at this point in the history

Commits on Sep 18, 2024

  1. kernel/syscall/obj: Add object management

    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>
    cxdong committed Sep 18, 2024
    Configuration menu
    Copy the full SHA
    147d7fc View commit details
    Browse the repository at this point in the history
  2. syscall/obj: Define ObjHandle for the user mode

    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>
    cxdong committed Sep 18, 2024
    Configuration menu
    Copy the full SHA
    24be6b7 View commit details
    Browse the repository at this point in the history