From bfc4d9c37b417ddd17a123912d878877986981d8 Mon Sep 17 00:00:00 2001 From: Patrick Roy Date: Wed, 2 Oct 2024 11:30:27 +0100 Subject: [PATCH] fix memory access benchmark panicking on ARM The benchmark tries to write to guest physical address 0, but on ARM guest memory doesn't start at 0, so when resolving the address we panicked. Fix this by instead simply using whatever address guest memory starts with. Signed-off-by: Patrick Roy --- src/vmm/benches/memory_access.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/vmm/benches/memory_access.rs b/src/vmm/benches/memory_access.rs index 81742d1ce37..0da710492f7 100644 --- a/src/vmm/benches/memory_access.rs +++ b/src/vmm/benches/memory_access.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 use criterion::{criterion_group, criterion_main, BatchSize, Criterion}; -use vm_memory::{GuestAddress, GuestMemory}; +use vm_memory::GuestMemory; use vmm::resources::VmResources; use vmm::vmm_config::machine_config::{HugePageConfig, VmConfig}; @@ -11,11 +11,10 @@ fn bench_single_page_fault(c: &mut Criterion, configuration: VmResources) { b.iter_batched( || { let memory = configuration.allocate_guest_memory().unwrap(); - let ptr = memory - .get_slice(GuestAddress(0), 1) - .unwrap() - .ptr_guard_mut() - .as_ptr(); + // Get a pointer to the first memory region (cannot do `.get_slice(GuestAddress(0), + // 1)`, because on ARM64 guest memory does not start at physical + // address 0). + let ptr = memory.iter().next().unwrap().as_ptr(); // fine to return both here, because ptr is not a reference into `memory` (e.g. no // self-referential structs are happening here)