qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] hostmem-file: fix pmem file size check
@ 2019-08-23 13:56 Stefan Hajnoczi
  2019-08-23 18:14 ` Eduardo Habkost
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Hajnoczi @ 2019-08-23 13:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Eduardo Habkost, Stefan Hajnoczi

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 <stefanha@redhat.com>
---
 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



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH] hostmem-file: fix pmem file size check
  2019-08-23 13:56 [Qemu-devel] [PATCH] hostmem-file: fix pmem file size check Stefan Hajnoczi
@ 2019-08-23 18:14 ` Eduardo Habkost
  0 siblings, 0 replies; 2+ messages in thread
From: Eduardo Habkost @ 2019-08-23 18:14 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: Igor Mammedov, qemu-devel

On Fri, Aug 23, 2019 at 02:56:32PM +0100, Stefan Hajnoczi wrote:
> 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 <stefanha@redhat.com>

Queued, thanks.

-- 
Eduardo


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-08-23 18:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-23 13:56 [Qemu-devel] [PATCH] hostmem-file: fix pmem file size check Stefan Hajnoczi
2019-08-23 18:14 ` Eduardo Habkost

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).