Skip to content

underhill_mem: add RCU implementation to synchronize bitmap changes #1383

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

Merged
merged 8 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2672,6 +2672,7 @@ name = "guestmem"
version = "0.0.0"
dependencies = [
"inspect",
"minircu",
"pal_event",
"sparse_mmap",
"thiserror 2.0.12",
Expand Down Expand Up @@ -4207,6 +4208,19 @@ dependencies = [
name = "minimal_rt_build"
version = "0.0.0"

[[package]]
name = "minircu"
version = "0.0.0"
dependencies = [
"event-listener",
"libc",
"pal_async",
"parking_lot",
"test_with_tracing",
"tracelimit",
"windows-sys 0.59.0",
]

[[package]]
name = "miniz_oxide"
version = "0.8.8"
Expand Down Expand Up @@ -7965,6 +7979,7 @@ dependencies = [
"libc",
"memory_range",
"mesh",
"minircu",
"pal",
"pal_async",
"pal_uring",
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ mesh_remote = { path = "support/mesh/mesh_remote" }
mesh_rpc = { path = "support/mesh/mesh_rpc" }
mesh_worker = { path = "support/mesh/mesh_worker" }
mesh_tracing = { path = "support/mesh_tracing" }
minircu = { path = "support/minircu" }
open_enum = { path = "support/open_enum" }
openssl_kdf = { path = "support/openssl_kdf" }
openssl_crypto_only = { path = "support/openssl_crypto_only" }
Expand Down
2 changes: 1 addition & 1 deletion openhcl/underhill_mem/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition.workspace = true
rust-version.workspace = true

[target.'cfg(target_os = "linux")'.dependencies]
guestmem.workspace = true
guestmem = { workspace = true, features = ["bitmap"] }
hcl.workspace = true
hv1_structs.workspace = true
hvdef.workspace = true
Expand Down
9 changes: 8 additions & 1 deletion openhcl/underhill_mem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,14 @@ impl ProtectIsolatedMemory for HardwareIsolatedMemoryProtector {
clear_bitmap.update_bitmap(range, false);
}

// TODO SNP: flush concurrent accessors.
// There may be other threads concurrently accessing these pages. We
// cannot change the page visibility state until these threads have
// stopped those accesses. Flush the RCU domain that `guestmem` uses in
// order to flush any threads accessing the pages. After this, we are
// guaranteed no threads are accessing these pages (unless the pages are
// also locked), since no bitmap currently allows access.
guestmem::rcu().synchronize_sync();

if let IsolationType::Snp = self.acceptor.isolation {
// We need to ensure that the guest TLB has been fully flushed since
// the unaccept operation is not guaranteed to do so in hardware,
Expand Down
1 change: 1 addition & 0 deletions openhcl/virt_mshv_vtl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ x86emu.workspace = true
inspect_counters.workspace = true
inspect = { workspace = true, features = ["std"] }
mesh.workspace = true
minircu.workspace = true
pal_async.workspace = true
pal_uring.workspace = true
pal.workspace = true
Expand Down
4 changes: 4 additions & 0 deletions openhcl/virt_mshv_vtl/src/processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,10 @@ impl<'p, T: Backing> Processor for UhProcessor<'p, T> {
.into();
}

// Quiesce RCU before running the VP to avoid having to synchronize with
// this CPU during memory protection updates.
minircu::global().quiesce();

T::run_vp(self, dev, &mut stop).await?;
self.kernel_returns += 1;
}
Expand Down
25 changes: 25 additions & 0 deletions support/minircu/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

[package]
name = "minircu"
rust-version.workspace = true
edition.workspace = true

[dependencies]
event-listener.workspace = true
parking_lot.workspace = true
tracelimit.workspace = true

[target.'cfg(target_os = "linux")'.dependencies]
libc.workspace = true

[target.'cfg(windows)'.dependencies]
windows-sys = { workspace = true, features = ["Win32_System_Threading"] }

[dev-dependencies]
pal_async.workspace = true
test_with_tracing.workspace = true

[lints]
workspace = true
Loading
Loading