From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, ehabkost@redhat.com,
"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [Qemu-devel] [PATCH v5 4/6] memfd: add hugetlb support
Date: Mon, 23 Oct 2017 10:59:08 +0100 [thread overview]
Message-ID: <20171023095910.23202-5-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <20171023095910.23202-1-marcandre.lureau@redhat.com>
Linux commit 749df87bd7bee5a79cef073f5d032ddb2b211de8 (v4.14-rc1)
added a new flag MFD_HUGETLB to memfd_create() that specify the file
to be created resides in the hugetlbfs filesystem. This is the
generic hugetlbfs filesystem not associated with any specific mount
point.
hugetlbfs does not support sealing operations, therefore specifying
MFD_ALLOW_SEALING with MFD_HUGETLB will result in EINVAL.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
include/qemu/memfd.h | 4 ++--
util/memfd.c | 13 ++++++++++---
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/include/qemu/memfd.h b/include/qemu/memfd.h
index b9d09873b5..1d3ecc7458 100644
--- a/include/qemu/memfd.h
+++ b/include/qemu/memfd.h
@@ -16,8 +16,8 @@
#define F_SEAL_WRITE 0x0008 /* prevent writes */
#endif
-int qemu_memfd_create(const char *name, size_t size, unsigned int seals,
- Error **errp);
+int qemu_memfd_create(const char *name, size_t size, bool hugetlb,
+ unsigned int seals, Error **errp);
void *qemu_memfd_alloc(const char *name, size_t size, unsigned int seals,
int *fd, Error **errp);
void qemu_memfd_free(void *ptr, size_t size, int fd);
diff --git a/util/memfd.c b/util/memfd.c
index f890976a0e..98294e84de 100644
--- a/util/memfd.c
+++ b/util/memfd.c
@@ -54,7 +54,11 @@ static int memfd_create(const char *name, unsigned int flags)
#define MFD_ALLOW_SEALING 0x0002U
#endif
-int qemu_memfd_create(const char *name, size_t size,
+#ifndef MFD_HUGETLB
+#define MFD_HUGETLB 0x0004U
+#endif
+
+int qemu_memfd_create(const char *name, size_t size, bool hugetlb,
unsigned int seals, Error **errp)
{
#ifdef CONFIG_LINUX
@@ -64,6 +68,9 @@ int qemu_memfd_create(const char *name, size_t size,
if (seals) {
flags |= MFD_ALLOW_SEALING;
}
+ if (hugetlb) {
+ flags |= MFD_HUGETLB;
+ }
mfd = memfd_create(name, flags);
if (mfd < 0) {
@@ -99,11 +106,11 @@ void *qemu_memfd_alloc(const char *name, size_t size, unsigned int seals,
int *fd, Error **errp)
{
void *ptr;
- int mfd = qemu_memfd_create(name, size, seals, NULL);
+ int mfd = qemu_memfd_create(name, size, false, seals, NULL);
/* some systems have memfd without sealing */
if (mfd == -1) {
- mfd = qemu_memfd_create(name, size, 0, NULL);
+ mfd = qemu_memfd_create(name, size, false, 0, NULL);
}
if (mfd == -1) {
--
2.15.0.rc0.40.gaefcc5f6f
next prev parent reply other threads:[~2017-10-23 9:59 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-23 9:59 [Qemu-devel] [PATCH v5 0/6] Add memfd memory backend Marc-André Lureau
2017-10-23 9:59 ` [Qemu-devel] [PATCH v5 1/6] memfd: split qemu_memfd_alloc() Marc-André Lureau
2017-10-23 11:02 ` Philippe Mathieu-Daudé
2017-10-23 9:59 ` [Qemu-devel] [PATCH v5 2/6] memfd: remove needless include Marc-André Lureau
2017-10-23 10:59 ` Philippe Mathieu-Daudé
2017-10-23 9:59 ` [Qemu-devel] [PATCH v5 3/6] memfd: add error argument, instead of perror() Marc-André Lureau
2017-10-23 9:59 ` Marc-André Lureau [this message]
2017-10-23 10:23 ` [Qemu-devel] [PATCH v5 4/6] memfd: add hugetlb support Daniel P. Berrange
2017-10-23 11:27 ` Marc-André Lureau
2017-10-23 11:33 ` Daniel P. Berrange
2017-10-23 9:59 ` [Qemu-devel] [PATCH v5 5/6] Add memfd based hostmem Marc-André Lureau
2017-10-23 11:36 ` Daniel P. Berrange
2017-10-23 11:41 ` Marc-André Lureau
2017-10-23 11:47 ` Daniel P. Berrange
2017-10-23 9:59 ` [Qemu-devel] [PATCH v5 6/6] tests: use memfd in vhost-user-test Marc-André Lureau
2017-10-23 10:26 ` Daniel P. Berrange
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=20171023095910.23202-5-marcandre.lureau@redhat.com \
--to=marcandre.lureau@redhat.com \
--cc=ehabkost@redhat.com \
--cc=pbonzini@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).