From a1d6e18f001e3d4b7c6a726db5fad724406f90ea Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Fri, 22 Sep 2023 10:45:50 +0200 Subject: [PATCH] virDomainMemoryDefValidate: Fix VIRTIO_MEM alignment check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Ján Tomko --- src/conf/domain_validate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index e423383e22..d14559cd73 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -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;