diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 712feb7b81..15a0ea4081 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -9086,25 +9086,6 @@ qemuBuildShmemCommandLine(virCommand *cmd, g_autoptr(virJSONValue) memProps = NULL; g_autoptr(virJSONValue) devProps = NULL; - if (shmem->size) { - /* - * Thanks to our parsing code, we have a guarantee that the - * size is power of two and is at least a mebibyte in size. - * But because it may change in the future, the checks are - * doubled in here. - */ - if (shmem->size & (shmem->size - 1)) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("shmem size must be a power of two")); - return -1; - } - if (shmem->size < 1024 * 1024) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("shmem size must be at least 1 MiB (1024 KiB)")); - return -1; - } - } - if (shmem->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("only 'pci' addresses are supported for the shared memory device")); diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index b22d3618fe..01f65c0866 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -5118,6 +5118,15 @@ static int qemuValidateDomainDeviceDefShmem(virDomainShmemDef *shmem, virQEMUCaps *qemuCaps) { + if (shmem->size > 0) { + if (shmem->size < 1024 * 1024 || + !VIR_IS_POW2(shmem->size)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("shmem size must be a power of 2 and at least 1 MiB (1024 KiB)")); + return -1; + } + } + switch (shmem->model) { case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", diff --git a/tests/qemuxml2argvdata/shmem-invalid-size.x86_64-latest.err b/tests/qemuxml2argvdata/shmem-invalid-size.x86_64-latest.err index 623bd8e5dd..5409cb73c2 100644 --- a/tests/qemuxml2argvdata/shmem-invalid-size.x86_64-latest.err +++ b/tests/qemuxml2argvdata/shmem-invalid-size.x86_64-latest.err @@ -1 +1 @@ -XML error: shmem size must be a power of two +XML error: shmem size must be a power of 2 and at least 1 MiB (1024 KiB) diff --git a/tests/qemuxml2argvdata/shmem-small-size.x86_64-latest.err b/tests/qemuxml2argvdata/shmem-small-size.x86_64-latest.err index b5fcd8b4cf..5409cb73c2 100644 --- a/tests/qemuxml2argvdata/shmem-small-size.x86_64-latest.err +++ b/tests/qemuxml2argvdata/shmem-small-size.x86_64-latest.err @@ -1 +1 @@ -XML error: shmem size must be at least 1 MiB (1024 KiB) +XML error: shmem size must be a power of 2 and at least 1 MiB (1024 KiB) diff --git a/tests/qemuxml2xmloutdata/shmem-invalid-size.x86_64-latest.xml b/tests/qemuxml2xmloutdata/shmem-invalid-size.x86_64-latest.xml deleted file mode 100644 index cc7b63da94..0000000000 --- a/tests/qemuxml2xmloutdata/shmem-invalid-size.x86_64-latest.xml +++ /dev/null @@ -1,34 +0,0 @@ - - QEMUGuest1 - c7a5fdbd-edaf-9455-926a-d65c16db1809 - 219136 - 219136 - 1 - - hvm - - - - qemu64 - - - destroy - restart - destroy - - /usr/bin/qemu-system-x86_64 - -
- - - - -