]> xenbits.xensource.com Git - libvirt.git/commitdiff
virDomainMemoryDefValidate: Fix VIRTIO_MEM alignment check
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 22 Sep 2023 08:45:50 +0000 (10:45 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 22 Sep 2023 14:37:10 +0000 (16:37 +0200)
Inside of virDomainMemoryDefValidate() there's a check that
address where a virtio-mem memory device is mapped to is a
multiple of its block size. But this check is off by a couple of
bits, because the memory address is in bytes while the block size
is in kibibytes. Therefore, when checking whether address is a
multiple of the block size, the latter has to be multiplied by a
factor of 1024.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/domain_validate.c

index e423383e22418a49d4d7b7e830758e182ae80f29..d14559cd7306019ac60ca3318af492b440253b7f 100644 (file)
@@ -2341,7 +2341,8 @@ virDomainMemoryDefValidate(const virDomainMemoryDef *mem,
             return -1;
         }
 
-        if (mem->target.virtio_mem.address % mem->target.virtio_mem.blocksize != 0) {
+        /* blocksize is stored in KiB while address is in bytes */
+        if (mem->target.virtio_mem.address % (mem->target.virtio_mem.blocksize * 1024) != 0) {
             virReportError(VIR_ERR_XML_DETAIL, "%s",
                            _("memory device address must be aligned to blocksize"));
             return -1;