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

alloc: initial TryBox implementation #196

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Commits on Feb 26, 2024

  1. alloc: initial TryBox implementation

    Introduce the alloc submodule and the TryBox type, a fork of the
    upstream alloc crate and Box type respectively. The new type behaves
    exactly like Box, except it only supports fallible allocations,
    meaning that users must always handle potential errors.
    
    Users must also explicitly set the allocator to use. Using a specific
    allocator by default like the standard library does is complicated.
    The standard library uses whichever allocator is set as global
    (via the #[global_allocator] macro), which can be accessed via a
    global instance (alloc::alloc::Global). However, the global instance
    is gated behind an unstable feature, and the macro cannot be
    reimplemented because it is a compiler intrinsic. As a workaround,
    one may add new higher level types in the future which use a specific
    allocator by default.
    
    The new type also has a few extra methods for convenience like
    try_default_in(), try_clone() and try_clone_in().
    
    Signed-off-by: Carlos López <[email protected]>
    00xc committed Feb 26, 2024
    Configuration menu
    Copy the full SHA
    7e2d047 View commit details
    Browse the repository at this point in the history
  2. mm/alloc: implement Allocator for SvsmAllocator

    In order to be used along with the new TryBox type, an allocator must
    implement the Allocator trait, so implement it for the current global
    allocator.
    
    Signed-off-by: Carlos López <[email protected]>
    00xc committed Feb 26, 2024
    Configuration menu
    Copy the full SHA
    7659fa6 View commit details
    Browse the repository at this point in the history
  3. error: add SvsmError::TryAlloc

    Add a new variant to hold a TryAllocError from the alloc submodule.
    This new error does not implement Copy, so SvsmError cannot implement
    it either.
    
    Signed-off-by: Carlos López <[email protected]>
    00xc committed Feb 26, 2024
    Configuration menu
    Copy the full SHA
    54a1cdf View commit details
    Browse the repository at this point in the history
  4. mm: add GlobalBox implementation

    Add a new type, GlobalBox, which wraps around the TryBox type but uses
    the global SvsmAllocator transparently. The new type implements
    AsRef<TryBox> and Into<TryBox>, so regular TryBox methods can also be
    used on the new type.
    
    Signed-off-by: Carlos López <[email protected]>
    00xc committed Feb 26, 2024
    Configuration menu
    Copy the full SHA
    918ff17 View commit details
    Browse the repository at this point in the history
  5. mm/pagetable: replace Box with GlobalBox

    Allocate PageTablePart structs with the new fallible-allocation-aware
    GlobalBox type.
    
    Signed-off-by: Carlos López <[email protected]>
    00xc committed Feb 26, 2024
    Configuration menu
    Copy the full SHA
    68f2daf View commit details
    Browse the repository at this point in the history
  6. greq: replace Box with GlobalBox

    Use the new fallible-allocation-aware GlobalBox type when allocating
    SNP request messages.
    
    Signed-off-by: Carlos López <[email protected]>
    00xc committed Feb 26, 2024
    Configuration menu
    Copy the full SHA
    8265a89 View commit details
    Browse the repository at this point in the history
  7. mm/vm: replace Box with GlobalBox

    Replace uses of Box with the new fallible-allocation-aware GlobalBox
    type. Unfortunately, replacing the Box used in the RB tree for
    virtual mappings is very involved.
    
    In short, the intrusive_collections crate provides an
    intrusive_adapter macro, which generates a new adapter type that
    handles the insertion and deletion of any type into an intrusive
    collection. Sadly, this macro is only prepared to work with the smart
    pointer types in the standard library. This is done by implementing
    the PointerOps trait for DefaultPointerOps<T>, where T is one of the
    regular smart pointer types (Rc, Arc, Box, etc.). The macro then
    generates an implementation of Adapter for the newly generated type,
    which uses the selected smart pointer.
    
    We define a substitute for DefaultPointerOps, CustomPointerOps, and
    implement PointerOps for CustomPointerOps<GlobalBox>. We then add a
    manual implementation of Adapter for VMMAdapter, which uses GlobalBox
    under the hood.
    
    Signed-off-by: Carlos López <[email protected]>
    00xc committed Feb 26, 2024
    Configuration menu
    Copy the full SHA
    54019fc View commit details
    Browse the repository at this point in the history
  8. mm/vm/mapping: replace Box with GlobalBox

    Replace uses of Box in the mapping API with the new
    fallible-allocation-aware GlobalBox type.
    
    Signed-off-by: Carlos López <[email protected]>
    00xc committed Feb 26, 2024
    Configuration menu
    Copy the full SHA
    8eec6ec View commit details
    Browse the repository at this point in the history
  9. sev/secrets_page: replace Box with GlobalBox

    Use the new fallible-allocation-aware GlobalBox type when allocating
    a new secrets page for the given VPML.
    
    Signed-off-by: Carlos López <[email protected]>
    00xc committed Feb 26, 2024
    Configuration menu
    Copy the full SHA
    6a05132 View commit details
    Browse the repository at this point in the history