Skip to content

Commit 3423312

Browse files
committed
vmem: Add stronger tlb invalidation barrier
Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
1 parent 33a6193 commit 3423312

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

‎src/hyperlight_guest_bin/src/arch/aarch64/paging.rs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ pub fn phys_to_virt(gpa: vmem::PhysAddr) -> Option<*mut u8> {
138138
}
139139

140140
pub mod barrier {
141+
use hyperlight_common::vmem;
142+
141143
/// # Architecture-specific (aarch64) notes
142144
///
143145
/// I_WZCBG from [1]:
@@ -171,4 +173,16 @@ pub mod barrier {
171173
);
172174
}
173175
}
176+
177+
#[inline(always)]
178+
pub fn downgrade_in_place(var: core::ops::Range<vmem::VirtAddr>) {
179+
unsafe {
180+
core::arch::asm!("dsb ish");
181+
// todo: use TLBI RVAE1IS if FEAT_TLBIRANGE is available
182+
for va in var.step_by(vmem::PAGE_SIZE) {
183+
core::arch::asm!("tlbi vae1is, {}", in(reg) va >> 12);
184+
}
185+
core::arch::asm!("dsb ish\nisb");
186+
}
187+
}
174188
}

‎src/hyperlight_guest_bin/src/arch/amd64/paging.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ pub fn phys_to_virt(gpa: vmem::PhysAddr) -> Option<*mut u8> {
153153

154154
/// Barriers that other code may need to use when updating page tables
155155
pub mod barrier {
156+
use hyperlight_common::vmem;
157+
156158
/// Call this function when a virtual address has just been made
157159
/// valid for the first time after the last tlb invalidate that
158160
/// affected it, and it will be used for the first time in the
@@ -204,4 +206,13 @@ pub mod barrier {
204206
", out("rax") _);
205207
}
206208
}
209+
210+
pub fn downgrade_in_place(var: core::ops::Range<vmem::VirtAddr>) {
211+
unsafe {
212+
// todo: use TLBI RVAE1IS if FEAT_TLBIRANGE is available
213+
for va in var.step_by(vmem::PAGE_SIZE) {
214+
core::arch::asm!("invlpg [{}]", in(reg) va, options(readonly, nostack, preserves_flags));
215+
}
216+
}
217+
}
207218
}

‎src/hyperlight_guest_bin/src/paging.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ mod arch;
88
pub use arch::{map_region, modify_mapping, phys_to_virt, virt_to_phys};
99
/// Barriers that other code may need to use when updating page tables
1010
pub mod barrier {
11+
/// Call this function when a virtual address has had its
12+
/// permissions changed in a way that makes previously-valid
13+
/// accesses invalid.
14+
///
15+
/// Range must be page-aligned.
16+
pub use arch::downgrade_in_place;
1117
/// Call this function when a virtual address has just been made
1218
/// valid for the first time after the last tlb invalidate that
1319
/// affected it, and it will be used for the first time in the

0 commit comments

Comments
 (0)