[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v6 11/12] hostmem-file: fix pmem file size check
From: |
Eduardo Habkost |
Subject: |
[Qemu-devel] [PULL v6 11/12] hostmem-file: fix pmem file size check |
Date: |
Wed, 28 Aug 2019 15:40:25 -0300 |
From: Stefan Hajnoczi <address@hidden>
Commit 314aec4a6e06844937f1677f6cba21981005f389 ("hostmem-file: reject
invalid pmem file sizes") added a file size check that verifies the
hostmem object's size parameter against the actual devdax pmem file.
This is useful because getting the size wrong results in confusing
errors inside the guest.
However, the code doesn't work properly for files where struct
stat::st_size is zero. Hostmem-file's ->alloc() function returns early
without setting an Error, causing the following assertion failure:
qemu/memory.c:2215: memory_region_get_ram_ptr: Assertion `mr->ram_block'
failed.
This patch handles the case where qemu_get_pmem_size() returns 0 but
there is no error.
Fixes: 314aec4a6e06844937f1677f6cba21981005f389
Signed-off-by: Stefan Hajnoczi <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Eduardo Habkost <address@hidden>
---
backends/hostmem-file.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
index 29e55c9195..ecc15e3eb0 100644
--- a/backends/hostmem-file.c
+++ b/backends/hostmem-file.c
@@ -67,12 +67,12 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error
**errp)
uint64_t size;
size = qemu_get_pmem_size(fb->mem_path, &local_err);
- if (!size) {
+ if (local_err) {
error_propagate(errp, local_err);
return;
}
- if (backend->size > size) {
+ if (size && backend->size > size) {
error_setg(errp, "size property %" PRIu64 " is larger than "
"pmem file \"%s\" size %" PRIu64, backend->size,
fb->mem_path, size);
--
2.21.0
- [Qemu-devel] [PULL v6 01/12] includes: remove stale [smp|max]_cpus externs, (continued)
- [Qemu-devel] [PULL v6 01/12] includes: remove stale [smp|max]_cpus externs, Eduardo Habkost, 2019/08/28
- [Qemu-devel] [PULL v6 02/12] hw/arm: simplify arm_load_dtb, Eduardo Habkost, 2019/08/28
- [Qemu-devel] [PULL v6 03/12] numa: move numa global variable nb_numa_nodes into MachineState, Eduardo Habkost, 2019/08/28
- [Qemu-devel] [PULL v6 04/12] numa: move numa global variable have_numa_distance into MachineState, Eduardo Habkost, 2019/08/28
- [Qemu-devel] [PULL v6 05/12] numa: move numa global variable numa_info into MachineState, Eduardo Habkost, 2019/08/28
- [Qemu-devel] [PULL v6 06/12] numa: Introduce MachineClass::auto_enable_numa for implicit NUMA node, Eduardo Habkost, 2019/08/28
- [Qemu-devel] [PULL v6 07/12] pc: Fix error message on die-id validation, Eduardo Habkost, 2019/08/28
- [Qemu-devel] [PULL v6 08/12] pc: Improve error message when die-id is omitted, Eduardo Habkost, 2019/08/28
- [Qemu-devel] [PULL v6 09/12] pc: Don't make die-id mandatory unless necessary, Eduardo Habkost, 2019/08/28
- [Qemu-devel] [PULL v6 10/12] qapi: report the default CPU type for each machine, Eduardo Habkost, 2019/08/28
- [Qemu-devel] [PULL v6 11/12] hostmem-file: fix pmem file size check,
Eduardo Habkost <=
- [Qemu-devel] [PULL v6 12/12] i386/vmmouse: Properly reset state, Eduardo Habkost, 2019/08/28