From: David Hildenbrand <da...@redhat.com> The spec states: "The device MUST set addr, region_size, usable_region_size, plugged_size, requested_size to multiples of block_size."
In some cases, we currently don't guarantee that for "addr": For example, when starting a VM with 4 GiB boot memory and a virtio-mem device with a block size of 2 GiB, "memaddr"/"addr" will be auto-assigned to 0x140000000 (5 GiB). We'll try to improve auto-assignment for memory devices next, to avoid bailing out in case memory device code selects a bad address. Note: The Linux driver doesn't support such big block sizes yet. Reviewed-by: Pankaj Gupta <pankaj.gupta.li...@gmail.com> Fixes: 910b25766b33 ("virtio-mem: Paravirtualized memory hot(un)plug") Cc: "Michael S. Tsirkin" <m...@redhat.com> Cc: Wei Yang <richardw.y...@linux.intel.com> Cc: Dr. David Alan Gilbert <dgilb...@redhat.com> Cc: Igor Mammedov <imamm...@redhat.com> Cc: Pankaj Gupta <pankaj.gupta.li...@gmail.com> Signed-off-by: David Hildenbrand <da...@redhat.com> Message-Id: <20201008083029.9504-2-da...@redhat.com> Reviewed-by: Michael S. Tsirkin <m...@redhat.com> Signed-off-by: Michael S. Tsirkin <m...@redhat.com> --- hw/virtio/virtio-mem.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c index 7c8ca9f28b..70200b4eac 100644 --- a/hw/virtio/virtio-mem.c +++ b/hw/virtio/virtio-mem.c @@ -449,6 +449,11 @@ static void virtio_mem_device_realize(DeviceState *dev, Error **errp) ")", VIRTIO_MEM_REQUESTED_SIZE_PROP, VIRTIO_MEM_BLOCK_SIZE_PROP, vmem->block_size); return; + } else if (!QEMU_IS_ALIGNED(vmem->addr, vmem->block_size)) { + error_setg(errp, "'%s' property has to be multiples of '%s' (0x%" PRIx64 + ")", VIRTIO_MEM_ADDR_PROP, VIRTIO_MEM_BLOCK_SIZE_PROP, + vmem->block_size); + return; } else if (!QEMU_IS_ALIGNED(memory_region_size(&vmem->memdev->mr), vmem->block_size)) { error_setg(errp, "'%s' property memdev size has to be multiples of" -- MST