Skip to content

Removed the OutBHandler and MemAccessHandler abstractions and related implementations. #732

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

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

Conversation

simongdavies
Copy link
Contributor

@simongdavies simongdavies commented Jul 24, 2025

This pull fixes #495. It removes the OutBHandler and MemAccessHandler related traits, types and structs.

Since there is only a single implementation the functions that these types abstracted over (handle_outb and handle_mem_access) the code can be simplified by calling these functions directly.

One implication of this change is that the Hypervisor now contains a MemMgrWrapper<T> which ultimately contains a HostMapping instance. Since the Hypervisor is Send + Sync this change would require HostMapping to be Send + Sync which is not automatically implemented as it contains a *mut u8 type. The solution that this PR implements is to remove the Sync constraint from the Hypervisor trait since its not possible to access a Sandbox concurrently from multiple threads.

There is probably some code in shared_mem that on the face of it does not seem necessary without multi threaded access but in the future when async guest io is implemented will still be needed so that is the only change made.

@simongdavies simongdavies added the kind/enhancement For PRs adding features, improving functionality, docs, tests, etc. label Jul 24, 2025
@simongdavies simongdavies marked this pull request as draft July 24, 2025 22:33
@simongdavies simongdavies changed the title Removed the OutBHandler and MemAccessHandler abstractions and related implementations. [WIP] Removed the OutBHandler and MemAccessHandler abstractions and related implementations. Jul 24, 2025
@simongdavies simongdavies changed the title [WIP] Removed the OutBHandler and MemAccessHandler abstractions and related implementations. Removed the OutBHandler and MemAccessHandler abstractions and related implementations. Jul 28, 2025
@simongdavies simongdavies marked this pull request as ready for review July 28, 2025 21:59
Copy link
Member

@syntactically syntactically left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The solution that this PR implements is to remove the Sync constraint from the Hypervisor trait since its not possible to access a Sandbox concurrently from multiple threads.

That seems like a reasonable constraint, especially given the performance cliffs that we see with accessing a KVM partition from multiple threads (and how easy it seems to be for people to run into that). Is there a compelling reason not to make the Hypervisor trait non-Send as well, at least for the temporary future?

I do think that in general, we are going to need to be able to split up the actual hypervisor handle and the access to the host side of the memory mapping, in order to support the async use case, where the hypervisor handler(s) might (at least sometimes) need to be in a different thread running the guest vcpu whilst the host is also accessing memory buffers for async parameter passing. However, that is something we can address later.

There is probably some code in shared_mem that on the face of it does not seem necessary without multi threaded access but in the future when async guest io is implemented will still be needed so that is the only change made.

Thanks for leaving this in; indeed some of this was preemptively written.

.take()
.ok_or_else(|| new_error!("mem_mgr should be initialized"))?;

let result = VirtualCPU::run(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there is a way to simplify the somewhat windy code flow around here and remove the need to take the mem mgr option out, but perhaps that's for another day.


/// The trait representing custom logic to handle the case when
/// a Hypervisor's virtual CPU (vCPU) informs Hyperlight a debug memory access
/// has been requested.
#[cfg(gdb)]
pub trait DbgMemAccessHandlerCaller: Send {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this trait also only has one (non-test) impl. Does it make sense to do the same thing as with the others and remove it?

Also, why remove the cfg(gdb) guards?

// We need to handle the borrow checker issue where we need both:
// - &mut MemMgrWrapper (from self.mem_mgr.as_mut())
// - &mut dyn Hypervisor (from self)
// We'll use a temporary approach to extract the mem_mgr temporarily
Copy link
Member

@syntactically syntactically Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to cfg gate this instead of doing the same thing in both cases (e.g. a measurable performance impact?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement For PRs adding features, improving functionality, docs, tests, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove OutBHandlerWrapper type
2 participants