domain_validate: Validate VIRTIO_PMEM address alignment

QEMU mandates the VIRTIO_PMEM address is aligned to a pagesize.
This is a very reasonable requirement. So much so, that it
deserves to be in hypervisor agnostic validation code
(virDomainMemoryDefValidate()). Not that any other hypervisor
would support VIRTIO_PMEM yet. But even if they did, this would
surely be still valid.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik 2023-09-22 10:07:28 +02:00
parent 1839c5c46e
commit d54b70a7e4

View File

@ -2221,6 +2221,7 @@ static int
virDomainMemoryDefValidate(const virDomainMemoryDef *mem,
const virDomainDef *def)
{
const long pagesize = virGetSystemPageSize();
unsigned long long thpSize;
/* Guest NUMA nodes are continuous and indexed from zero. */
@ -2295,6 +2296,14 @@ virDomainMemoryDefValidate(const virDomainMemoryDef *mem,
_("virtio-pmem does not support NUMA nodes"));
return -1;
}
if (pagesize > 0 &&
mem->target.virtio_pmem.address % pagesize != 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("memory address must be aligned to %1$ld bytes"),
pagesize);
return -1;
}
break;
case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: