From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org, David Hildenbrand <david@redhat.com>,
Igor Mammedov <imammedo@redhat.com>
Cc: "David Gibson" <david@gibson.dropbear.id.au>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [PATCH] backends/hostmem: Fix support of memory-backend-memfd in qemu_maxrampagesize()
Date: Wed, 10 Aug 2022 08:32:04 +0200 [thread overview]
Message-ID: <20220810063204.3589543-1-thuth@redhat.com> (raw)
It is currently not possible yet to use "memory-backend-memfd" on s390x
with hugepages enabled. This problem is caused by qemu_maxrampagesize()
not taking memory-backend-memfd objects into account yet, so the code
in s390_memory_init() fails to enable the huge page support there via
s390_set_max_pagesize(). Fix it by looking at the memory-backend-memfd
in the host_memory_backend_pagesize() function, too.
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2116496
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
include/sysemu/hostmem.h | 8 +++++++-
backends/hostmem-memfd.c | 2 --
backends/hostmem.c | 27 +++++++++++++++++----------
3 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/include/sysemu/hostmem.h b/include/sysemu/hostmem.h
index 9ff5c16963..d983ae6c01 100644
--- a/include/sysemu/hostmem.h
+++ b/include/sysemu/hostmem.h
@@ -34,10 +34,16 @@ OBJECT_DECLARE_TYPE(HostMemoryBackend, HostMemoryBackendClass,
/* hostmem-file.c */
/**
* @TYPE_MEMORY_BACKEND_FILE:
- * name of backend that uses mmap on a file descriptor
+ * name of backend that uses mmap on a file
*/
#define TYPE_MEMORY_BACKEND_FILE "memory-backend-file"
+/* hostmem-memfd.c */
+/**
+ * @TYPE_MEMORY_BACKEND_MEMFD:
+ * name of backend that uses mmap on a memfd file descriptor
+ */
+#define TYPE_MEMORY_BACKEND_MEMFD "memory-backend-memfd"
/**
* HostMemoryBackendClass:
diff --git a/backends/hostmem-memfd.c b/backends/hostmem-memfd.c
index 3fc85c3db8..1ab2085e49 100644
--- a/backends/hostmem-memfd.c
+++ b/backends/hostmem-memfd.c
@@ -18,8 +18,6 @@
#include "qapi/error.h"
#include "qom/object.h"
-#define TYPE_MEMORY_BACKEND_MEMFD "memory-backend-memfd"
-
OBJECT_DECLARE_SIMPLE_TYPE(HostMemoryBackendMemfd, MEMORY_BACKEND_MEMFD)
diff --git a/backends/hostmem.c b/backends/hostmem.c
index 624bb7ecd3..ebce887105 100644
--- a/backends/hostmem.c
+++ b/backends/hostmem.c
@@ -306,22 +306,29 @@ bool host_memory_backend_is_mapped(HostMemoryBackend *backend)
return backend->is_mapped;
}
-#ifdef __linux__
size_t host_memory_backend_pagesize(HostMemoryBackend *memdev)
{
+ size_t pagesize = 0;
+
+#ifdef __linux__
Object *obj = OBJECT(memdev);
- char *path = object_property_get_str(obj, "mem-path", NULL);
- size_t pagesize = qemu_mempath_getpagesize(path);
- g_free(path);
+ if (object_dynamic_cast(obj, TYPE_MEMORY_BACKEND_FILE)) {
+ char *path = object_property_get_str(obj, "mem-path", NULL);
+ pagesize = qemu_mempath_getpagesize(path);
+ g_free(path);
+ } else if (object_dynamic_cast(obj, TYPE_MEMORY_BACKEND_MEMFD) &&
+ object_property_get_bool(obj, "hugetlb", &error_abort)) {
+ pagesize = object_property_get_int(obj, "hugetlbsize", &error_abort);
+ }
+#endif
+
+ if (!pagesize) {
+ pagesize = qemu_real_host_page_size();
+ }
+
return pagesize;
}
-#else
-size_t host_memory_backend_pagesize(HostMemoryBackend *memdev)
-{
- return qemu_real_host_page_size();
-}
-#endif
static void
host_memory_backend_memory_complete(UserCreatable *uc, Error **errp)
--
2.31.1
next reply other threads:[~2022-08-10 6:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-10 6:32 Thomas Huth [this message]
2022-08-10 7:32 ` [PATCH] backends/hostmem: Fix support of memory-backend-memfd in qemu_maxrampagesize() David Hildenbrand
2022-08-10 8:11 ` Thomas Huth
2022-08-10 8:31 ` David Hildenbrand
2022-08-10 9:20 ` Thomas Huth
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=20220810063204.3589543-1-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=david@redhat.com \
--cc=imammedo@redhat.com \
--cc=marcandre.lureau@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).