qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Michal Privoznik <mprivozn@redhat.com>
To: qemu-devel@nongnu.org
Cc: david@redhat.com, imammedo@redhat.com
Subject: [PATCH 2/3] backends/hostmem: Warn on qemu_madvise() failures
Date: Tue, 28 May 2024 18:15:08 +0200	[thread overview]
Message-ID: <b51b2a1cda33115b3370a8b3a4a4e6e9c10566d2.1716912651.git.mprivozn@redhat.com> (raw)
In-Reply-To: <cover.1716912651.git.mprivozn@redhat.com>

If user sets .merge or .dump attributes qemu_madvise() is called
with corresponding advice. But it is never checked for failure
which may mislead users into thinking the attribute is set
correctly.I believe at this point it's too late to report errors
in that case but let's report a warning at least.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 backends/hostmem.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/backends/hostmem.c b/backends/hostmem.c
index eb9682b4a8..1a6fd1c714 100644
--- a/backends/hostmem.c
+++ b/backends/hostmem.c
@@ -14,6 +14,7 @@
 #include "sysemu/hostmem.h"
 #include "hw/boards.h"
 #include "qapi/error.h"
+#include "qemu/error-report.h"
 #include "qapi/qapi-builtin-visit.h"
 #include "qapi/visitor.h"
 #include "qemu/config-file.h"
@@ -178,8 +179,11 @@ static void host_memory_backend_set_merge(Object *obj, bool value, Error **errp)
         void *ptr = memory_region_get_ram_ptr(&backend->mr);
         uint64_t sz = memory_region_size(&backend->mr);
 
-        qemu_madvise(ptr, sz,
-                     value ? QEMU_MADV_MERGEABLE : QEMU_MADV_UNMERGEABLE);
+        if (qemu_madvise(ptr, sz,
+                         value ? QEMU_MADV_MERGEABLE : QEMU_MADV_UNMERGEABLE)) {
+            warn_report("Couldn't change property 'merge' on '%s': %s",
+                        object_get_typename(obj), strerror(errno));
+        }
         backend->merge = value;
     }
 }
@@ -204,8 +208,11 @@ static void host_memory_backend_set_dump(Object *obj, bool value, Error **errp)
         void *ptr = memory_region_get_ram_ptr(&backend->mr);
         uint64_t sz = memory_region_size(&backend->mr);
 
-        qemu_madvise(ptr, sz,
-                     value ? QEMU_MADV_DODUMP : QEMU_MADV_DONTDUMP);
+        if (qemu_madvise(ptr, sz,
+                         value ? QEMU_MADV_DODUMP : QEMU_MADV_DONTDUMP)) {
+            warn_report("Couldn't change property 'dump' on '%s': %s",
+                        object_get_typename(obj), strerror(errno));
+        }
         backend->dump = value;
     }
 }
@@ -337,11 +344,15 @@ host_memory_backend_memory_complete(UserCreatable *uc, Error **errp)
     ptr = memory_region_get_ram_ptr(&backend->mr);
     sz = memory_region_size(&backend->mr);
 
-    if (backend->merge) {
-        qemu_madvise(ptr, sz, QEMU_MADV_MERGEABLE);
+    if (backend->merge &&
+        qemu_madvise(ptr, sz, QEMU_MADV_MERGEABLE)) {
+        warn_report("Couldn't set property 'merge' on '%s': %s",
+                    object_get_typename(OBJECT(uc)), strerror(errno));
     }
-    if (!backend->dump) {
-        qemu_madvise(ptr, sz, QEMU_MADV_DONTDUMP);
+    if (!backend->dump &&
+        qemu_madvise(ptr, sz, QEMU_MADV_DONTDUMP)) {
+        warn_report("Couldn't set property 'dump' on '%s': %s",
+                    object_get_typename(OBJECT(uc)), strerror(errno));
     }
 #ifdef CONFIG_NUMA
     unsigned long lastbit = find_last_bit(backend->host_nodes, MAX_NODES);
-- 
2.44.1



  parent reply	other threads:[~2024-05-28 16:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-28 16:15 [PATCH 0/3] backends/hostmem: Round up memory size for qemu_madvise() and mbind() Michal Privoznik
2024-05-28 16:15 ` [PATCH 1/3] osdep: Make qemu_madvise() to set errno in all cases Michal Privoznik
2024-05-28 16:51   ` David Hildenbrand
2024-05-28 16:15 ` Michal Privoznik [this message]
2024-05-28 16:15 ` [PATCH 3/3] backends/hostmem: Round up memory size for qemu_madvise() and mbind() Michal Privoznik
2024-05-28 16:47   ` David Hildenbrand
2024-05-29  6:48     ` Michal Prívozník
2024-05-29 12:30       ` David Hildenbrand
2024-05-28 17:22   ` Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b51b2a1cda33115b3370a8b3a4a4e6e9c10566d2.1716912651.git.mprivozn@redhat.com \
    --to=mprivozn@redhat.com \
    --cc=david@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).