vm_control: change VmMemoryRegionId to use GuestAddress

We don't actually need the guest frame number in the VmMemoryRegionId
(it is just an opaque value that needs to be unique for each region),
and the frame number calculation depends on the page size, so it's
simpler to just use the guest physical address itself without shifting
it.

Change-Id: I75d181c7e07f79b5e0ba0bf0a1174d4f71263bb8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6027193
Reviewed-by: Elie Kheirallah <khei@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
Daniel Verkamp 2024-11-15 12:12:34 -08:00 committed by crosvm LUCI
parent e9de2c4770
commit d39e3bbc39

View file

@ -712,9 +712,8 @@ fn try_map_to_prepared_region(
return Some(VmMemoryResponse::Err(err));
}
let guest_address = guest_address.0 + dest_offset;
let gfn = guest_address >> 12;
let region_id = VmMemoryRegionId(gfn);
let guest_address = GuestAddress(guest_address.0 + dest_offset);
let region_id = VmMemoryRegionId(guest_address);
region_state.registered_memory.insert(
region_id,
RegisteredMemory::FixedMapping {
@ -808,7 +807,7 @@ impl VmMemoryRequest {
Err(e) => return VmMemoryResponse::Err(e),
};
let region_id = VmMemoryRegionId(guest_addr.0 >> 12);
let region_id = VmMemoryRegionId(guest_addr);
if let (Some(descriptor), Some(iommu_client)) = (descriptor, iommu_client) {
let request =
VirtioIOMMURequest::VfioCommand(VirtioIOMMUVfioCommand::VfioDmabufMap {
@ -925,7 +924,7 @@ impl VmMemoryRequest {
Err(e) => return VmMemoryResponse::Err(e),
};
let region_id = VmMemoryRegionId(guest_addr.0 >> 12);
let region_id = VmMemoryRegionId(guest_addr);
region_state
.registered_memory
@ -1055,8 +1054,8 @@ impl VmMemoryRequest {
#[derive(Serialize, Deserialize, Debug, PartialOrd, PartialEq, Eq, Ord, Clone, Copy)]
/// Identifer for registered memory regions. Globally unique.
// The current implementation uses gfn as the unique identifier.
pub struct VmMemoryRegionId(u64);
// The current implementation uses guest physical address as the unique identifier.
pub struct VmMemoryRegionId(GuestAddress);
#[derive(Serialize, Deserialize, Debug)]
pub enum VmMemoryResponse {