[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v3 03/31] virtio-mem: Make sure "usable_region_size" is always mul
From: |
Michael S. Tsirkin |
Subject: |
[PULL v3 03/31] virtio-mem: Make sure "usable_region_size" is always multiples of the block size |
Date: |
Wed, 4 Nov 2020 13:41:24 -0500 |
From: David Hildenbrand <david@redhat.com>
The spec states:
"The device MUST set addr, region_size, usable_region_size, plugged_size,
requested_size to multiples of block_size."
With block sizes > 256MB, we currently wouldn't guarantee that for the
usable_region_size.
Note that we cannot exceed the region_size, as we already enforce the
alignment there properly.
Fixes: 910b25766b33 ("virtio-mem: Paravirtualized memory hot(un)plug")
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Wei Yang <richardw.yang@linux.intel.com>
Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Pankaj Gupta <pankaj.gupta.linux@gmail.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
Message-Id: <20201008083029.9504-3-david@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/virtio/virtio-mem.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c
index 70200b4eac..461ac68ee8 100644
--- a/hw/virtio/virtio-mem.c
+++ b/hw/virtio/virtio-mem.c
@@ -227,6 +227,9 @@ static void virtio_mem_resize_usable_region(VirtIOMEM *vmem,
uint64_t newsize = MIN(memory_region_size(&vmem->memdev->mr),
requested_size + VIRTIO_MEM_USABLE_EXTENT);
+ /* The usable region size always has to be multiples of the block size. */
+ newsize = QEMU_ALIGN_UP(newsize, vmem->block_size);
+
if (!requested_size) {
newsize = 0;
}
--
MST
- [PULL v3 00/31] pc,pci,vhost,virtio: fixes, Michael S. Tsirkin, 2020/11/04
- [PULL v3 01/31] pc: comment style fixup, Michael S. Tsirkin, 2020/11/04
- [PULL v3 02/31] virtio-mem: Make sure "addr" is always multiples of the block size, Michael S. Tsirkin, 2020/11/04
- [PULL v3 03/31] virtio-mem: Make sure "usable_region_size" is always multiples of the block size,
Michael S. Tsirkin <=
- [PULL v3 04/31] virtio-mem: Probe THP size to determine default block size, Michael S. Tsirkin, 2020/11/04
- [PULL v3 05/31] memory-device: Support big alignment requirements, Michael S. Tsirkin, 2020/11/04
- [PULL v3 06/31] memory-device: Add get_min_alignment() callback, Michael S. Tsirkin, 2020/11/04
- [PULL v3 08/31] hw/acpi : Don't use '#' flag of printf format, Michael S. Tsirkin, 2020/11/04
- [PULL v3 07/31] virito-mem: Implement get_min_alignment(), Michael S. Tsirkin, 2020/11/04
- [PULL v3 09/31] hw/acpi : add space before the open parenthesis '(', Michael S. Tsirkin, 2020/11/04
- [PULL v3 11/31] hw/virtio/vhost-backend: Fix Coverity CID 1432871, Michael S. Tsirkin, 2020/11/04
- [PULL v3 12/31] hw/smbios: Fix leaked fd in save_opt_one() error path, Michael S. Tsirkin, 2020/11/04
- [PULL v3 13/31] virtio-iommu: Fix virtio_iommu_mr(), Michael S. Tsirkin, 2020/11/04
- [PULL v3 14/31] virtio-iommu: Store memory region in endpoint struct, Michael S. Tsirkin, 2020/11/04