mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-03 11:25:20 +00:00
vmm: virtio-mem: Enforce alignment and size requirements
The virtio-mem driver is generating some warnings regarding both size and alignment of the virtio-mem region if not based on 128MiB: The alignment of the physical start address can make some memory unusable. The alignment of the physical end address can make some memory unusable. For these reasons, the current patch enforces virtio-mem regions to be 128MiB aligned and checks the size provided by the user is a multiple of 128MiB. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
eb7b923e22
commit
1798ed8194
@ -42,8 +42,11 @@ use vmm_sys_util::eventfd::EventFd;
|
||||
const QUEUE_SIZE: u16 = 128;
|
||||
const QUEUE_SIZES: &[u16] = &[QUEUE_SIZE];
|
||||
|
||||
// 128MiB is the standard memory block size in Linux. A virtio-mem region must
|
||||
// be aligned on this size, and the region size must be a multiple of it.
|
||||
pub const VIRTIO_MEM_ALIGN_SIZE: u64 = 128 * 1024 * 1024;
|
||||
// Use 2 MiB alignment so transparent hugepages can be used by KVM.
|
||||
pub const VIRTIO_MEM_DEFAULT_BLOCK_SIZE: u64 = 512 * 4096;
|
||||
const VIRTIO_MEM_DEFAULT_BLOCK_SIZE: u64 = 512 * 4096;
|
||||
const VIRTIO_MEM_USABLE_EXTENT: u64 = 256 * 1024 * 1024;
|
||||
|
||||
// Request processed successfully, applicable for
|
||||
@ -702,13 +705,12 @@ impl Mem {
|
||||
) -> io::Result<Mem> {
|
||||
let region_len = region.len();
|
||||
|
||||
if region_len != region_len / VIRTIO_MEM_DEFAULT_BLOCK_SIZE * VIRTIO_MEM_DEFAULT_BLOCK_SIZE
|
||||
{
|
||||
if region_len != region_len / VIRTIO_MEM_ALIGN_SIZE * VIRTIO_MEM_ALIGN_SIZE {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!(
|
||||
"Virtio-mem size is not aligned with {}",
|
||||
VIRTIO_MEM_DEFAULT_BLOCK_SIZE
|
||||
VIRTIO_MEM_ALIGN_SIZE
|
||||
),
|
||||
));
|
||||
}
|
||||
|
@ -523,11 +523,9 @@ impl MemoryManager {
|
||||
} else {
|
||||
// Alignment must be "natural" i.e. same as size of block
|
||||
let start_addr = GuestAddress(
|
||||
(start_of_device_area.0
|
||||
+ virtio_devices::VIRTIO_MEM_DEFAULT_BLOCK_SIZE
|
||||
- 1)
|
||||
/ virtio_devices::VIRTIO_MEM_DEFAULT_BLOCK_SIZE
|
||||
* virtio_devices::VIRTIO_MEM_DEFAULT_BLOCK_SIZE,
|
||||
(start_of_device_area.0 + virtio_devices::VIRTIO_MEM_ALIGN_SIZE - 1)
|
||||
/ virtio_devices::VIRTIO_MEM_ALIGN_SIZE
|
||||
* virtio_devices::VIRTIO_MEM_ALIGN_SIZE,
|
||||
);
|
||||
|
||||
let region = MemoryManager::create_ram_region(
|
||||
|
Loading…
Reference in New Issue
Block a user