Skip to content

Commit

Permalink
memfd: add hugetlb support
Browse files Browse the repository at this point in the history
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 in v4.14, therefore
specifying MFD_ALLOW_SEALING with MFD_HUGETLB will result in EINVAL.

However, I added sealing support in "[PATCH v3 0/9] memfd: add sealing
to hugetlb-backed memory" series, queued in -mm tree for v4.16.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20180201132757.23063-3-marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
elmarco authored and bonzini committed Feb 7, 2018
1 parent 0f2956f commit c5b2a9e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions include/qemu/memfd.h
Expand Up @@ -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);
Expand Down
13 changes: 10 additions & 3 deletions util/memfd.c
Expand Up @@ -52,7 +52,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
Expand All @@ -62,6 +66,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) {
Expand Down Expand Up @@ -97,11 +104,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) {
Expand Down

0 comments on commit c5b2a9e

Please sign in to comment.