mirror of
https://github.com/google/alioth.git
synced 2024-11-28 09:26:21 +00:00
fix(mem/aarch64): create guest memory with memfd
Shared memory is required to make vhost-user devices work. Signed-off-by: Changyuan Lyu <changyuanl@google.com>
This commit is contained in:
parent
01d387b0f0
commit
79ec0077b4
1 changed files with 19 additions and 20 deletions
|
@ -95,30 +95,29 @@ where
|
|||
pub fn create_ram(&self) -> Result<()> {
|
||||
let mem_size = self.config.mem_size;
|
||||
let memory = &self.memory;
|
||||
if mem_size > RAM_32_SIZE {
|
||||
memory.add_region(
|
||||
AddrOpt::Fixed(RAM_32_START),
|
||||
Arc::new(MemRegion::with_mapped(
|
||||
ArcMemPages::from_anonymous(RAM_32_SIZE as usize, None)?,
|
||||
MemRegionType::Ram,
|
||||
)),
|
||||
)?;
|
||||
|
||||
let low_mem_size = std::cmp::min(mem_size, RAM_32_SIZE);
|
||||
#[cfg(target_os = "linux")]
|
||||
let pages_low = ArcMemPages::from_memfd(low_mem_size as usize, None, Some(c"ram-low"))?;
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
let pages_low = ArcMemPages::from_anonymous(low_mem_size as usize, None)?;
|
||||
memory.add_region(
|
||||
AddrOpt::Fixed(RAM_32_START),
|
||||
Arc::new(MemRegion::with_mapped(pages_low, MemRegionType::Ram)),
|
||||
)?;
|
||||
|
||||
let high_mem_size = mem_size.saturating_sub(RAM_32_SIZE) as usize;
|
||||
if high_mem_size > 0 {
|
||||
#[cfg(target_os = "linux")]
|
||||
let pages_high = ArcMemPages::from_memfd(high_mem_size, None, Some(c"ram-high"))?;
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
let pages_high = ArcMemPages::from_anonymous(high_mem_size, None)?;
|
||||
memory.add_region(
|
||||
AddrOpt::Fixed(MEM_64_START),
|
||||
Arc::new(MemRegion::with_mapped(
|
||||
ArcMemPages::from_anonymous((mem_size - RAM_32_SIZE) as usize, None)?,
|
||||
MemRegionType::Ram,
|
||||
)),
|
||||
)?;
|
||||
} else {
|
||||
memory.add_region(
|
||||
AddrOpt::Fixed(RAM_32_START),
|
||||
Arc::new(MemRegion::with_mapped(
|
||||
ArcMemPages::from_anonymous(mem_size as usize, None)?,
|
||||
MemRegionType::Ram,
|
||||
)),
|
||||
Arc::new(MemRegion::with_mapped(pages_high, MemRegionType::Ram)),
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue