-
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
alloc: initial TryBox
implementation
#196
base: main
Are you sure you want to change the base?
Commits on Feb 26, 2024
-
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]>
Configuration menu - View commit details
-
Copy full SHA for 7e2d047 - Browse repository at this point
Copy the full SHA 7e2d047View commit details -
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]>
Configuration menu - View commit details
-
Copy full SHA for 7659fa6 - Browse repository at this point
Copy the full SHA 7659fa6View commit details -
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]>
Configuration menu - View commit details
-
Copy full SHA for 54a1cdf - Browse repository at this point
Copy the full SHA 54a1cdfView commit details -
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]>
Configuration menu - View commit details
-
Copy full SHA for 918ff17 - Browse repository at this point
Copy the full SHA 918ff17View commit details -
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]>
Configuration menu - View commit details
-
Copy full SHA for 68f2daf - Browse repository at this point
Copy the full SHA 68f2dafView commit details -
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]>
Configuration menu - View commit details
-
Copy full SHA for 8265a89 - Browse repository at this point
Copy the full SHA 8265a89View commit details -
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]>
Configuration menu - View commit details
-
Copy full SHA for 54019fc - Browse repository at this point
Copy the full SHA 54019fcView commit details -
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]>
Configuration menu - View commit details
-
Copy full SHA for 8eec6ec - Browse repository at this point
Copy the full SHA 8eec6ecView commit details -
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]>
Configuration menu - View commit details
-
Copy full SHA for 6a05132 - Browse repository at this point
Copy the full SHA 6a05132View commit details