[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 3/4] backends/hostmem: Report error on qemu_madvise() failures
From: |
Michal Privoznik |
Subject: |
[PATCH v2 3/4] backends/hostmem: Report error on qemu_madvise() failures |
Date: |
Fri, 31 May 2024 09:28:59 +0200 |
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. Report an appropriate error.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
backends/hostmem.c | 36 ++++++++++++++++++++++++++++--------
1 file changed, 28 insertions(+), 8 deletions(-)
diff --git a/backends/hostmem.c b/backends/hostmem.c
index eb9682b4a8..012a8c190f 100644
--- a/backends/hostmem.c
+++ b/backends/hostmem.c
@@ -178,8 +178,14 @@ 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))
{
+ error_setg_errno(errp, errno,
+ "Couldn't change property 'merge' on '%s'",
+ object_get_typename(obj));
+ return;
+ }
+
backend->merge = value;
}
}
@@ -204,8 +210,14 @@ 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)) {
+ error_setg_errno(errp, errno,
+ "Couldn't change property 'dump' on '%s'",
+ object_get_typename(obj));
+ return;
+ }
+
backend->dump = value;
}
}
@@ -337,11 +349,19 @@ 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)) {
+ error_setg_errno(errp, errno,
+ "Couldn't set property 'merge' on '%s'",
+ object_get_typename(OBJECT(uc)));
+ return;
}
- if (!backend->dump) {
- qemu_madvise(ptr, sz, QEMU_MADV_DONTDUMP);
+ if (!backend->dump &&
+ qemu_madvise(ptr, sz, QEMU_MADV_DONTDUMP)) {
+ error_setg_errno(errp, errno,
+ "Couldn't set property 'dump' on '%s'",
+ object_get_typename(OBJECT(uc)));
+ return;
}
#ifdef CONFIG_NUMA
unsigned long lastbit = find_last_bit(backend->host_nodes, MAX_NODES);
--
2.44.1
- [PATCH v2 2/4] osdep: Make qemu_madvise() return ENOSYS on unsupported OSes, (continued)
[PATCH v2 3/4] backends/hostmem: Report error on qemu_madvise() failures,
Michal Privoznik <=
[PATCH v2 4/4] backends/hostmem: Report error when memory size is unaligned, Michal Privoznik, 2024/05/31