Commit 72497845 authored by Marc-André Lureau's avatar Marc-André Lureau Committed by Linus Torvalds

memfd-test: test hugetlbfs sealing

Remove most of the special-casing of hugetlbfs now that sealing is
supported.

Link: http://lkml.kernel.org/r/20171107122800.25517-7-marcandre.lureau@redhat.comSigned-off-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: default avatarMike Kravetz <mike.kravetz@oracle.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 47b9012e
...@@ -513,6 +513,10 @@ static void mfd_assert_grow_write(int fd) ...@@ -513,6 +513,10 @@ static void mfd_assert_grow_write(int fd)
static char *buf; static char *buf;
ssize_t l; ssize_t l;
/* hugetlbfs does not support write */
if (hugetlbfs_test)
return;
buf = malloc(mfd_def_size * 8); buf = malloc(mfd_def_size * 8);
if (!buf) { if (!buf) {
printf("malloc(%zu) failed: %m\n", mfd_def_size * 8); printf("malloc(%zu) failed: %m\n", mfd_def_size * 8);
...@@ -533,6 +537,10 @@ static void mfd_fail_grow_write(int fd) ...@@ -533,6 +537,10 @@ static void mfd_fail_grow_write(int fd)
static char *buf; static char *buf;
ssize_t l; ssize_t l;
/* hugetlbfs does not support write */
if (hugetlbfs_test)
return;
buf = malloc(mfd_def_size * 8); buf = malloc(mfd_def_size * 8);
if (!buf) { if (!buf) {
printf("malloc(%zu) failed: %m\n", mfd_def_size * 8); printf("malloc(%zu) failed: %m\n", mfd_def_size * 8);
...@@ -627,7 +635,6 @@ static void test_create(void) ...@@ -627,7 +635,6 @@ static void test_create(void)
fd = mfd_assert_new("", 0, MFD_CLOEXEC); fd = mfd_assert_new("", 0, MFD_CLOEXEC);
close(fd); close(fd);
if (!hugetlbfs_test) {
/* verify MFD_ALLOW_SEALING is allowed */ /* verify MFD_ALLOW_SEALING is allowed */
fd = mfd_assert_new("", 0, MFD_ALLOW_SEALING); fd = mfd_assert_new("", 0, MFD_ALLOW_SEALING);
close(fd); close(fd);
...@@ -635,10 +642,6 @@ static void test_create(void) ...@@ -635,10 +642,6 @@ static void test_create(void)
/* verify MFD_ALLOW_SEALING | MFD_CLOEXEC is allowed */ /* verify MFD_ALLOW_SEALING | MFD_CLOEXEC is allowed */
fd = mfd_assert_new("", 0, MFD_ALLOW_SEALING | MFD_CLOEXEC); fd = mfd_assert_new("", 0, MFD_ALLOW_SEALING | MFD_CLOEXEC);
close(fd); close(fd);
} else {
/* sealing is not supported on hugetlbfs */
mfd_fail_new("", MFD_ALLOW_SEALING);
}
} }
/* /*
...@@ -649,10 +652,6 @@ static void test_basic(void) ...@@ -649,10 +652,6 @@ static void test_basic(void)
{ {
int fd; int fd;
/* hugetlbfs does not contain sealing support */
if (hugetlbfs_test)
return;
printf("%s BASIC\n", MEMFD_STR); printf("%s BASIC\n", MEMFD_STR);
fd = mfd_assert_new("kern_memfd_basic", fd = mfd_assert_new("kern_memfd_basic",
...@@ -697,28 +696,6 @@ static void test_basic(void) ...@@ -697,28 +696,6 @@ static void test_basic(void)
close(fd); close(fd);
} }
/*
* hugetlbfs doesn't support seals or write, so just verify grow and shrink
* on a hugetlbfs file created via memfd_create.
*/
static void test_hugetlbfs_grow_shrink(void)
{
int fd;
printf("%s HUGETLBFS-GROW-SHRINK\n", MEMFD_STR);
fd = mfd_assert_new("kern_memfd_seal_write",
mfd_def_size,
MFD_CLOEXEC);
mfd_assert_read(fd);
mfd_assert_write(fd);
mfd_assert_shrink(fd);
mfd_assert_grow(fd);
close(fd);
}
/* /*
* Test SEAL_WRITE * Test SEAL_WRITE
* Test whether SEAL_WRITE actually prevents modifications. * Test whether SEAL_WRITE actually prevents modifications.
...@@ -727,13 +704,6 @@ static void test_seal_write(void) ...@@ -727,13 +704,6 @@ static void test_seal_write(void)
{ {
int fd; int fd;
/*
* hugetlbfs does not contain sealing or write support. Just test
* basic grow and shrink via test_hugetlbfs_grow_shrink.
*/
if (hugetlbfs_test)
return test_hugetlbfs_grow_shrink();
printf("%s SEAL-WRITE\n", MEMFD_STR); printf("%s SEAL-WRITE\n", MEMFD_STR);
fd = mfd_assert_new("kern_memfd_seal_write", fd = mfd_assert_new("kern_memfd_seal_write",
...@@ -760,10 +730,6 @@ static void test_seal_shrink(void) ...@@ -760,10 +730,6 @@ static void test_seal_shrink(void)
{ {
int fd; int fd;
/* hugetlbfs does not contain sealing support */
if (hugetlbfs_test)
return;
printf("%s SEAL-SHRINK\n", MEMFD_STR); printf("%s SEAL-SHRINK\n", MEMFD_STR);
fd = mfd_assert_new("kern_memfd_seal_shrink", fd = mfd_assert_new("kern_memfd_seal_shrink",
...@@ -790,10 +756,6 @@ static void test_seal_grow(void) ...@@ -790,10 +756,6 @@ static void test_seal_grow(void)
{ {
int fd; int fd;
/* hugetlbfs does not contain sealing support */
if (hugetlbfs_test)
return;
printf("%s SEAL-GROW\n", MEMFD_STR); printf("%s SEAL-GROW\n", MEMFD_STR);
fd = mfd_assert_new("kern_memfd_seal_grow", fd = mfd_assert_new("kern_memfd_seal_grow",
...@@ -820,10 +782,6 @@ static void test_seal_resize(void) ...@@ -820,10 +782,6 @@ static void test_seal_resize(void)
{ {
int fd; int fd;
/* hugetlbfs does not contain sealing support */
if (hugetlbfs_test)
return;
printf("%s SEAL-RESIZE\n", MEMFD_STR); printf("%s SEAL-RESIZE\n", MEMFD_STR);
fd = mfd_assert_new("kern_memfd_seal_resize", fd = mfd_assert_new("kern_memfd_seal_resize",
...@@ -842,32 +800,6 @@ static void test_seal_resize(void) ...@@ -842,32 +800,6 @@ static void test_seal_resize(void)
close(fd); close(fd);
} }
/*
* hugetlbfs does not support seals. Basic test to dup the memfd created
* fd and perform some basic operations on it.
*/
static void hugetlbfs_dup(char *b_suffix)
{
int fd, fd2;
printf("%s HUGETLBFS-DUP %s\n", MEMFD_STR, b_suffix);
fd = mfd_assert_new("kern_memfd_share_dup",
mfd_def_size,
MFD_CLOEXEC);
fd2 = mfd_assert_dup(fd);
mfd_assert_read(fd);
mfd_assert_write(fd);
mfd_assert_shrink(fd2);
mfd_assert_grow(fd2);
close(fd2);
close(fd);
}
/* /*
* Test sharing via dup() * Test sharing via dup()
* Test that seals are shared between dupped FDs and they're all equal. * Test that seals are shared between dupped FDs and they're all equal.
...@@ -876,15 +808,6 @@ static void test_share_dup(char *banner, char *b_suffix) ...@@ -876,15 +808,6 @@ static void test_share_dup(char *banner, char *b_suffix)
{ {
int fd, fd2; int fd, fd2;
/*
* hugetlbfs does not contain sealing support. Perform some
* basic testing on dup'ed fd instead via hugetlbfs_dup.
*/
if (hugetlbfs_test) {
hugetlbfs_dup(b_suffix);
return;
}
printf("%s %s %s\n", MEMFD_STR, banner, b_suffix); printf("%s %s %s\n", MEMFD_STR, banner, b_suffix);
fd = mfd_assert_new("kern_memfd_share_dup", fd = mfd_assert_new("kern_memfd_share_dup",
...@@ -927,10 +850,6 @@ static void test_share_mmap(char *banner, char *b_suffix) ...@@ -927,10 +850,6 @@ static void test_share_mmap(char *banner, char *b_suffix)
int fd; int fd;
void *p; void *p;
/* hugetlbfs does not contain sealing support */
if (hugetlbfs_test)
return;
printf("%s %s %s\n", MEMFD_STR, banner, b_suffix); printf("%s %s %s\n", MEMFD_STR, banner, b_suffix);
fd = mfd_assert_new("kern_memfd_share_mmap", fd = mfd_assert_new("kern_memfd_share_mmap",
...@@ -955,32 +874,6 @@ static void test_share_mmap(char *banner, char *b_suffix) ...@@ -955,32 +874,6 @@ static void test_share_mmap(char *banner, char *b_suffix)
close(fd); close(fd);
} }
/*
* Basic test to make sure we can open the hugetlbfs fd via /proc and
* perform some simple operations on it.
*/
static void hugetlbfs_proc_open(char *b_suffix)
{
int fd, fd2;
printf("%s HUGETLBFS-PROC-OPEN %s\n", MEMFD_STR, b_suffix);
fd = mfd_assert_new("kern_memfd_share_open",
mfd_def_size,
MFD_CLOEXEC);
fd2 = mfd_assert_open(fd, O_RDWR, 0);
mfd_assert_read(fd);
mfd_assert_write(fd);
mfd_assert_shrink(fd2);
mfd_assert_grow(fd2);
close(fd2);
close(fd);
}
/* /*
* Test sealing with open(/proc/self/fd/%d) * Test sealing with open(/proc/self/fd/%d)
* Via /proc we can get access to a separate file-context for the same memfd. * Via /proc we can get access to a separate file-context for the same memfd.
...@@ -991,15 +884,6 @@ static void test_share_open(char *banner, char *b_suffix) ...@@ -991,15 +884,6 @@ static void test_share_open(char *banner, char *b_suffix)
{ {
int fd, fd2; int fd, fd2;
/*
* hugetlbfs does not contain sealing support. So test basic
* functionality of using /proc fd via hugetlbfs_proc_open
*/
if (hugetlbfs_test) {
hugetlbfs_proc_open(b_suffix);
return;
}
printf("%s %s %s\n", MEMFD_STR, banner, b_suffix); printf("%s %s %s\n", MEMFD_STR, banner, b_suffix);
fd = mfd_assert_new("kern_memfd_share_open", fd = mfd_assert_new("kern_memfd_share_open",
...@@ -1043,10 +927,6 @@ static void test_share_fork(char *banner, char *b_suffix) ...@@ -1043,10 +927,6 @@ static void test_share_fork(char *banner, char *b_suffix)
int fd; int fd;
pid_t pid; pid_t pid;
/* hugetlbfs does not contain sealing support */
if (hugetlbfs_test)
return;
printf("%s %s %s\n", MEMFD_STR, banner, b_suffix); printf("%s %s %s\n", MEMFD_STR, banner, b_suffix);
fd = mfd_assert_new("kern_memfd_share_fork", fd = mfd_assert_new("kern_memfd_share_fork",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment