Added memfd_create() testsuite
v5 cover Added memfd_create() testsuite
memfd_create() is a syscall that creates an anonymous file. This syscall was originally introduced in "File Sealing & memfd_create()" patchset by David Herrmann <[email protected]>.
My patchset is a partial port of memfd_create() testsuite to LTP, with lapi extended as necessary. Code that runs _dup, _mmap and _open tests in multi-threaded environment was not ported yet.
V2: fixed LTP style problems, added syscall numbers for each arch
V3: fixed more style problems, moved fallocate.h to include/lapi V4:
* fixed more style problems
V5:
* (really) fixed broken syscall availability detection
* fixed more style problems
* fixed checking write() return value
* memfd_create_common is now a library
Jakub Racek (6):
Added syscall numbers for memfd_create
Added memfd_create() lapi flags
Added fcntl() lapi flags
move fallocate.h to lapi
syscalls: added memfd_create dir and memfd_create/memfd_create01.c syscalls/memfd_create02.c: added new test
include/lapi/fallocate.h | 66 +++ include/lapi/fcntl.h | 25 ++ include/lapi/memfd.h | 27 ++ runtest/syscalls | 3 + testcases/kernel/include/aarch64.in | 1 + testcases/kernel/include/arm.in | 1 + testcases/kernel/include/hppa.in | 1 + testcases/kernel/include/i386.in | 1 + testcases/kernel/include/ia64.in | 1 + testcases/kernel/include/powerpc.in | 1 + testcases/kernel/include/powerpc64.in | 1 + testcases/kernel/include/s390.in | 1 + testcases/kernel/include/s390x.in | 1 + testcases/kernel/include/sh.in | 1 + testcases/kernel/include/sparc.in | 1 + testcases/kernel/include/sparc64.in | 1 + testcases/kernel/include/x86_64.in | 1 + testcases/kernel/syscalls/.gitignore | 2 + testcases/kernel/syscalls/fallocate/fallocate.h | 70 ---- testcases/kernel/syscalls/fallocate/fallocate01.c | 2 +- testcases/kernel/syscalls/fallocate/fallocate02.c | 2 +- testcases/kernel/syscalls/fallocate/fallocate03.c | 2 +- testcases/kernel/syscalls/fallocate/fallocate04.c | 2 +- testcases/kernel/syscalls/memfd_create/Makefile | 23 ++ .../kernel/syscalls/memfd_create/memfd_create01.c | 270 +++++++++++++ .../kernel/syscalls/memfd_create/memfd_create02.c | 94 +++++ .../syscalls/memfd_create/memfd_create_common.c | 446 +++++++++++++++++++++ .../syscalls/memfd_create/memfd_create_common.h | 152 +++++++ 28 files changed, 1125 insertions(+), 74 deletions(-) create mode 100644 include/lapi/fallocate.h create mode 100644 include/lapi/memfd.h delete mode 100644 testcases/kernel/syscalls/fallocate/fallocate.h create mode 100644 testcases/kernel/syscalls/memfd_create/Makefile create mode 100644 testcases/kernel/syscalls/memfd_create/memfd_create01.c create mode 100644 testcases/kernel/syscalls/memfd_create/memfd_create02.c create mode 100644 testcases/kernel/syscalls/memfd_create/memfd_create_common.c create mode 100644 testcases/kernel/syscalls/memfd_create/memfd_create_common.h
Signature · 1 line
1.8.3.1
PATCH v5 1/6 Added syscall numbers for memfd_create
--- testcases/kernel/include/aarch64.in | 1 + testcases/kernel/include/arm.in | 1 + testcases/kernel/include/hppa.in | 1 + testcases/kernel/include/i386.in | 1 + testcases/kernel/include/ia64.in | 1 + testcases/kernel/include/powerpc.in | 1 + testcases/kernel/include/powerpc64.in | 1 + testcases/kernel/include/s390.in | 1 + testcases/kernel/include/s390x.in | 1 + testcases/kernel/include/sh.in | 1 + testcases/kernel/include/sparc.in | 1 + testcases/kernel/include/sparc64.in | 1 + testcases/kernel/include/x86_64.in | 1 + 13 files changed, 13 insertions(+)
testcases/kernel/include/aarch64.in +1 -0
@@ -255,3 +255,4 @@ setns 268 sendmmsg 269 kcmp 272 getrandom 278 +memfd_create 279
testcases/kernel/include/arm.in +1 -0
@@ -338,3 +338,4 @@ sched_setattr (__NR_SYSCALL_BASE+380) sched_getattr (__NR_SYSCALL_BASE+381) renameat2 (__NR_SYSCALL_BASE+382) getrandom (__NR_SYSCALL_BASE+384) +memfd_create (__NR_SYSCALL_BASE+385)
testcases/kernel/include/hppa.in +1 -0
@@ -15,3 +15,4 @@ faccessat (__NR_openat + 12) splice 291 tee 293 vmsplice 294 +memfd_create 340
testcases/kernel/include/i386.in +1 -0
@@ -338,3 +338,4 @@ sched_setattr 351 sched_getattr 352 renameat2 354 getrandom 355 +memfd_create 356
testcases/kernel/include/ia64.in +1 -0
@@ -294,3 +294,4 @@ fanotify_mark 1324 prlimit64 1325 renameat2 1338 getrandom 1339 +memfd_create 1340
testcases/kernel/include/powerpc.in +1 -0
@@ -345,3 +345,4 @@ sched_setattr 355 sched_getattr 356 renameat2 357 getrandom 359 +memfd_create 360
testcases/kernel/include/powerpc64.in +1 -0
@@ -345,3 +345,4 @@ sched_setattr 355 sched_getattr 356 renameat2 357 getrandom 359 +memfd_create 360
testcases/kernel/include/s390.in +1 -0
@@ -329,3 +329,4 @@ sched_setattr 345 sched_getattr 346 renameat2 347 getrandom 349 +memfd_create 350
testcases/kernel/include/s390x.in +1 -0
@@ -329,3 +329,4 @@ sched_setattr 345 sched_getattr 346 renameat2 347 getrandom 349 +memfd_create 350
testcases/kernel/include/sh.in +1 -0
@@ -362,3 +362,4 @@ fanotify_init 367 fanotify_mark 368 prlimit64 369 kcmp 378 +memfd_create 385
testcases/kernel/include/sparc.in +1 -0
@@ -334,3 +334,4 @@ prlimit64 331 kcmp 341 renameat2 345 getrandom 347 +memfd_create 348
testcases/kernel/include/sparc64.in +1 -0
@@ -310,3 +310,4 @@ prlimit64 331 kcmp 341 renameat2 345 getrandom 347 +memfd_create 348
testcases/kernel/include/x86_64.in +1 -0
@@ -305,3 +305,4 @@ sched_setattr 314 sched_getattr 315 renameat2 316 getrandom 318 +memfd_create 319
Signature · 1 line
1.8.3.1
PATCH v5 2/6 Added memfd_create() lapi flags
In reply to Jakub Racek--- include/lapi/memfd.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 include/lapi/memfd.h
include/lapi/memfd.h new file +27 -0
@@ -0,0 +1,27 @@ +/* +* Copyright (C) 2017 Red Hat, Inc. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* This program is distributed in the hope that it would be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#ifndef LAPI_MEMFD_H +#define LAPI_MEMFD_H + +/* flags for memfd_create(2) (unsigned int) */ +#ifndef MFD_CLOEXEC +# define MFD_CLOEXEC 0x0001U +#endif +#ifndef MFD_ALLOW_SEALING +# define MFD_ALLOW_SEALING 0x0002U +#endif + +#endif
Signature · 1 line
1.8.3.1
PATCH v5 3/6 Added fcntl() lapi flags
In reply to Jakub Racek--- include/lapi/fcntl.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
include/lapi/fcntl.h +25 -0
@@ -50,6 +50,31 @@# define F_GETPIPE_SZ 1032#endif +/* +* Set/Get seals +*/ +#ifndef F_ADD_SEALS +# define F_ADD_SEALS (1033) +#endif + +#ifndef F_GET_SEALS +# define F_GET_SEALS (1034) +#endif + +#ifndef F_SEAL_SEAL +# define F_SEAL_SEAL 0x0001/* prevent further seals from being set */ +#endif + +#ifndef F_SEAL_SHRINK +# define F_SEAL_SHRINK 0x0002/* prevent file from shrinking */ +#endif +#ifndef F_SEAL_GROW +# define F_SEAL_GROW 0x0004/* prevent file from growing */ +#endif +#ifndef F_SEAL_WRITE +# define F_SEAL_WRITE 0x0008/* prevent writes */ +#endif +#ifndef F_OWNER_PGRP # define F_OWNER_PGRP 2#endif
Signature · 1 line
1.8.3.1
PATCH v5 4/6 move fallocate.h to lapi
In reply to Jakub Racek--- include/lapi/fallocate.h | 66 +++++++++++++++++++++ testcases/kernel/syscalls/fallocate/fallocate.h | 70 ----------------------- testcases/kernel/syscalls/fallocate/fallocate01.c | 2 +- testcases/kernel/syscalls/fallocate/fallocate02.c | 2 +- testcases/kernel/syscalls/fallocate/fallocate03.c | 2 +- testcases/kernel/syscalls/fallocate/fallocate04.c | 2 +- 6 files changed, 70 insertions(+), 74 deletions(-) create mode 100644 include/lapi/fallocate.h delete mode 100644 testcases/kernel/syscalls/fallocate/fallocate.h
include/lapi/fallocate.h new file +66 -0
@@ -0,0 +1,66 @@ +/* +* Copyright (c) International Business Machines Corp., 2007 +* Copyright (c) 2014 Fujitsu Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Library General Public License for more details. +* +*/ + +#ifndef FALLOCATE_H +#define FALLOCATE_H + +#include <sys/types.h> +#include <endian.h> +#include "config.h" +#include "lapi/abisize.h" +#include "linux_syscall_numbers.h" + +#ifndef SEEK_HOLE +# define SEEK_HOLE 4 +#endif + +#ifndef FALLOC_FL_KEEP_SIZE +# define FALLOC_FL_KEEP_SIZE 0x01 +#endif + +#ifndef FALLOC_FL_PUNCH_HOLE +# define FALLOC_FL_PUNCH_HOLE 0x02 +#endif + +#ifndef FALLOC_FL_COLLAPSE_RANGE +# define FALLOC_FL_COLLAPSE_RANGE 0x08 +#endif + +#ifndef FALLOC_FL_ZERO_RANGE +# define FALLOC_FL_ZERO_RANGE 0x10 +#endif + +#ifndef FALLOC_FL_INSERT_RANGE +# define FALLOC_FL_INSERT_RANGE 0x20 +#endif + +#if !defined(HAVE_FALLOCATE ) +static inline long fallocate (int fd,int mode,loff_t offset,loff_t len) +{ +/* Deal with 32bit ABIs that have 64bit syscalls. */ +# if LTP_USE_64_ABI +return ltp_syscall (__NR_fallocate, fd, mode, offset, len); +# else +return (long )ltp_syscall (__NR_fallocate, fd, mode, +__LONG_LONG_PAIR ((off_t) (offset >>32 ), + (off_t ) offset), +__LONG_LONG_PAIR ((off_t) (len >>32 ), + (off_t ) len)); +# endif +} +#endif + +#endif /* FALLOCATE_H */
testcases/kernel/syscalls/fallocate/fallocate.h deleted +0 -70
70 lines not on this page · raw message
testcases/kernel/syscalls/fallocate/fallocate01.c +1 -1
@@ -100,7 +100,7 @@#include <sys/utsname.h> #include "test.h" -#include "fallocate.h" +#include "lapi/fallocate.h" #include "lapi/fcntl.h" #define BLOCKS_WRITTEN 12
testcases/kernel/syscalls/fallocate/fallocate02.c +1 -1
@@ -39,7 +39,7 @@#include "test.h" #include "safe_macros.h" -#include "fallocate.h" +#include "lapi/fallocate.h" #define BLOCKS_WRITTEN 12#ifdef TEST_DEFAULT
testcases/kernel/syscalls/fallocate/fallocate03.c +1 -1
@@ -96,7 +96,7 @@#include <sys/utsname.h> #include "test.h" -#include "fallocate.h" +#include "lapi/fallocate.h" #define BLOCKS_WRITTEN 12#define HOLE_SIZE_IN_BLOCKS 12
testcases/kernel/syscalls/fallocate/fallocate04.c +1 -1
@@ -32,7 +32,7 @@#include "test.h" #include "safe_macros.h" -#include "fallocate.h" +#include "lapi/fallocate.h" char *TCID ="fallocate04" ;int TST_TOTAL =5 ;
Signature · 1 line
1.8.3.1
PATCH v5 5/6 syscalls: added memfd_create dir and memfd_create/memfd_create01.c
In reply to Jakub Racek--- runtest/syscalls | 2 + testcases/kernel/syscalls/.gitignore | 1 + testcases/kernel/syscalls/memfd_create/Makefile | 23 ++ .../kernel/syscalls/memfd_create/memfd_create01.c | 270 +++++++++++++ .../syscalls/memfd_create/memfd_create_common.c | 446 +++++++++++++++++++++ .../syscalls/memfd_create/memfd_create_common.h | 152 +++++++ 6 files changed, 894 insertions(+) create mode 100644 testcases/kernel/syscalls/memfd_create/Makefile create mode 100644 testcases/kernel/syscalls/memfd_create/memfd_create01.c create mode 100644 testcases/kernel/syscalls/memfd_create/memfd_create_common.c create mode 100644 testcases/kernel/syscalls/memfd_create/memfd_create_common.h
runtest/syscalls +2 -0
@@ -1450,3 +1450,5 @@ futex_wake03 futex_wake03 futex_wake04 futex_wake04 futex_wait_bitset01 futex_wait_bitset01 futex_wait_bitset02 futex_wait_bitset02 + +memfd_create01 memfd_create01
testcases/kernel/syscalls/.gitignore +1 -0
@@ -1118,3 +1118,4 @@ /fanotify/fanotify06 /perf_event_open/perf_event_open01 /perf_event_open/perf_event_open02 +/memfd_create/memfd_create01
testcases/kernel/syscalls/memfd_create/Makefile new file +23 -0
@@ -0,0 +1,23 @@ +# +# Copyright (C) 2017 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it would be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +FILTER_OUT_MAKE_TARGETS := memfd_create_common + +include $(top_srcdir)/include/mk/generic_leaf_target.mk + +$(MAKE_TARGETS): %: %.o memfd_create_common.o
testcases/kernel/syscalls/memfd_create/memfd_create01.c new file +270 -0
270 lines not on this page · raw message
testcases/kernel/syscalls/memfd_create/memfd_create_common.c new file +446 -0
446 lines not on this page · raw message
testcases/kernel/syscalls/memfd_create/memfd_create_common.h new file +152 -0
152 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v5 5/6 syscalls: added memfd_create dir and memfd_create/memfd_create01.c
Hi!
Patchset pushed with cosmetic chnages to this patch (see diff below), thanks.
testcases/kernel/syscalls/memfd_create/memfd_create01.c +1 -1
@@ -75,7 +75,7 @@ static void test_seal_write(int fd)CHECK_MFD_NON_WRITEABLE (fd);CHECK_MFD_SHRINKABLE (fd);CHECK_MFD_GROWABLE (fd); -CHECK_NON_GROWABLE_BY_WRITE (fd); +CHECK_MFD_NON_GROWABLE_BY_WRITE (fd); }
*** Added MFD here just for consistency
/*
@@ -109,7 +109,7 @@ static void test_seal_grow(int fd)
CHECK_MFD_WRITEABLE(fd); CHECK_MFD_SHRINKABLE(fd); CHECK_MFD_NON_GROWABLE(fd);
- CHECK_NON_GROWABLE_BY_WRITE(fd);
+ CHECK_MFD_NON_GROWABLE_BY_WRITE(fd);
}
/*
@@ -126,7 +126,7 @@ static void test_seal_resize(int fd)
CHECK_MFD_WRITEABLE(fd); CHECK_MFD_NON_SHRINKABLE(fd); CHECK_MFD_NON_GROWABLE(fd);
- CHECK_NON_GROWABLE_BY_WRITE(fd);
+ CHECK_MFD_NON_GROWABLE_BY_WRITE(fd);
}
/*
testcases/kernel/syscalls/memfd_create/memfd_create_common.c +16 -16
@@ -13,22 +13,22 @@* */ -#define _GNU_SOURCE - -#include <sys/types.h> -#include <sys/syscall.h> -#include <sys/uio.h> -#include <lapi/fallocate.h> -#include <lapi/fcntl.h> -#include <lapi/memfd.h> -#include <errno.h> -#include <string.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -#define TST_NO_DEFAULT_MAIN -#include <tst_test.h> +#define _GNU_SOURCE + +#include <sys/types.h> +#include <sys/syscall.h> +#include <sys/uio.h> +#include <lapi/fallocate.h> +#include <lapi/fcntl.h> +#include <lapi/memfd.h> +#include <errno.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#define TST_NO_DEFAULT_MAIN +#include <tst_test.h>
*** Removed spaces before #
#include "linux_syscall_numbers.h"
@@ -146,7 +146,8 @@ void check_mfd_fail_new(const char *filename, const int lineno,
fd = sys_memfd_create(name, flags);
if (fd >= 0) {
safe_close(filename, lineno, NULL, fd);
- tst_brk(TFAIL, "memfd_create(%s, %d) succeeded unexpectedly",
+ tst_brk_(filename, lineno, TFAIL,
+ "memfd_create(%s, %d) succeeded unexpectedly",
name, flags);
}
*** Added forgotten filename and lineno to the message
@@ -172,6 +173,7 @@ void check_mmap_fail(const char *file, const int lineno, void *addr,
size_t length, int prot, int flags, int fd, off_t offset)
{
if (mmap(addr, length, prot, flags, fd, offset) != MAP_FAILED) {
+ safe_munmap(file, lineno, NULL, addr, length);
tst_res_(file, lineno, TFAIL,
"mmap(%p, %zu, %i, %i, %i, %zi) succeeded unexpectedly", addr, length, prot, flags, fd, offset);
@@ -191,6 +193,19 @@ void check_munmap(const char *file, const int lineno, void *p, size_t length)
tst_res_(file, lineno, TPASS, "munmap(%p, %ld) succeeded", p, length);
}
*** Added forgotten munmap
+void check_mfd_has_seals(const char *file, const int lineno, int fd, int seals) +{
+ int ret = SAFE_FCNTL((fd), F_GET_SEALS);
+ if (ret != seals) {
+ tst_brk_(file, lineno, TFAIL,
+ "fd %d doesn't have expected seals (%d expected %d)",
+ fd, ret, seals);
+ }
+
+ tst_res_(file, lineno, TPASS,
+ "fd %d has expected seals (%d)", fd, seals);
+}
*** Changed this macro for a function and make it print the values of seals
void check_mprotect(const char *file, const int lineno, void *addr,
size_t length, int prot)
{
@@ -297,7 +312,7 @@ void check_mfd_writeable(const char *filename, const int lineno, int fd)
/* verify write() succeeds */
safe_write(filename, lineno, NULL, 1, fd, "\0\0\0\0", 4); tst_res_(filename, lineno, TPASS, "write(%d, %s, %d) succeeded", fd,
- "\0\0\0\0", 4);
+ "\\0\\0\\0\\0", 4);
** Changed this to print literal '\0\0\0\0' instead of random pointer
/* verify PROT_READ | PROT_WRITE is allowed */ p = check_mmap(filename, lineno, NULL, MFD_DEF_SIZE,
testcases/kernel/syscalls/memfd_create/memfd_create_common.h +4 -8
@@ -43,13 +43,7 @@ check_munmap(__FILE__, __LINE__, (p), (length))#define CHECK_MFD_HAS_SEALS (fd, seals) \ - do { \ - if (SAFE_FCNTL((fd), F_GET_SEALS) != (seals)) { \ - tst_brk(TFAIL, "fd %d doesn't have expected seals", \ - (fd)); \ - } \ - tst_res(TPASS, "fd %d has expected seals", (fd)); \ - } while (0) + check_mfd_has_seals(__FILE__, __LINE__, (fd), (seals));#define CHECK_MFD_ADD_SEALS (fd, seals) \ ({int r = SAFE_FCNTL((fd), F_ADD_SEALS, (seals)); \
@@ -92,7 +86,7 @@#define CHECK_MFD_GROWABLE_BY_WRITE (fd) \ check_mfd_growable_by_write(__FILE__, __LINE__, (fd)) -#define CHECK_NON_GROWABLE_BY_WRITE (fd) \ +#define CHECK_MFD_NON_GROWABLE_BY_WRITE (fd) \ check_mfd_non_growable_by_write(__FILE__, __LINE__, (fd))void assert_have_memfd_create (const char *filename,const int lineno);
@@ -119,6 +113,8 @@ void check_mmap_fail(const char *file, const int lineno, void *addr,void check_munmap (const char *file,const int lineno,void *p,size_t length); +void check_mfd_has_seals (const char *file,const int lineno,int fd,int seals); +void check_mprotect (const char *file,const int lineno,void *addr,size_t length,int prot);
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v5 5/6 syscalls: added memfd_create dir and memfd_create/memfd_create01.c
Hi,
thank you for the reviews. I learned a lot from that.
I'm also glad it finally made it through.
Best regards,
Jakub Racek
Quoted 175 lines · Cyril Hrubis
Hi!
Patchset pushed with cosmetic chnages to this patch (see diff below), thanks.testcases/kernel/syscalls/memfd_create/memfd_create01.c +1
-1@@ -75,7 +75,7 @@ static void test_seal_write(int fd)CHECK_MFD_NON_WRITEABLE (fd);CHECK_MFD_SHRINKABLE (fd);CHECK_MFD_GROWABLE (fd); -CHECK_NON_GROWABLE_BY_WRITE (fd); +CHECK_MFD_NON_GROWABLE_BY_WRITE (fd); } *** Added MFD here just for consistency/*
testcases/kernel/syscalls/memfd_create/memfd_create01.c +2
-2@@ -109,7 +109,7 @@ static void test_seal_grow(int fd)CHECK_MFD_WRITEABLE (fd);CHECK_MFD_SHRINKABLE (fd);CHECK_MFD_NON_GROWABLE (fd); -CHECK_NON_GROWABLE_BY_WRITE (fd); +CHECK_MFD_NON_GROWABLE_BY_WRITE (fd); }/* @@ -126,7 +126,7 @@ static void test_seal_resize(int fd)CHECK_MFD_WRITEABLE (fd);CHECK_MFD_NON_SHRINKABLE (fd);CHECK_MFD_NON_GROWABLE (fd); -CHECK_NON_GROWABLE_BY_WRITE (fd); +CHECK_MFD_NON_GROWABLE_BY_WRITE (fd); }/* testcases/kernel/syscalls/memfd_create/memfd_create_common.c +16
-16@@ -13,22 +13,22 @@* */ -#define _GNU_SOURCE - -#include <sys/types.h> -#include <sys/syscall.h> -#include <sys/uio.h> -#include <lapi/fallocate.h> -#include <lapi/fcntl.h> -#include <lapi/memfd.h> -#include <errno.h> -#include <string.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -#define TST_NO_DEFAULT_MAIN -#include <tst_test.h> +#define _GNU_SOURCE + +#include <sys/types.h> +#include <sys/syscall.h> +#include <sys/uio.h> +#include <lapi/fallocate.h> +#include <lapi/fcntl.h> +#include <lapi/memfd.h> +#include <errno.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#define TST_NO_DEFAULT_MAIN +#include <tst_test.h> *** Removed spaces before ##include "
linux_syscall_numbers.h"testcases/kernel/syscalls/memfd_create/memfd_create_common.c +2
-1@@ -146,7 +146,8 @@ void check_mfd_fail_new(const char *filename, const int lineno, fd =sys_memfd_create (name, flags);if (fd >=0 ) {safe_close (filename, lineno,NULL , fd); -tst_brk (TFAIL ,"memfd_create(%s, %d) succeeded unexpectedly" , +tst_brk_ (filename, lineno,TFAIL , +"memfd_create(%s, %d) succeeded unexpectedly" , name, flags); }*** Added forgotten filename and lineno to the message
testcases/kernel/syscalls/memfd_create/memfd_create_common.c +13
-0@@ -172,6 +173,7 @@ void check_mmap_fail(const char *file, const int lineno, void *addr, size_t length, int prot, int flags, int fd, off_t offset) { if (mmap(addr, length, prot, flags, fd, offset) != MAP_FAILED) { +safe_munmap (file ,lineno ,NULL ,addr ,length );tst_res_ (file, lineno,TFAIL ,"mmap(%p, %zu, %i, %i, %i, %zi) succeeded unexpectedly" , addr, length, prot, flags, fd, offset);@@ -191,6 +193,19 @@ void check_munmap(const char *file, const int lineno, void *p, size_t length)tst_res_ (file, lineno,TPASS ,"munmap(%p, %ld) succeeded" , p, length); } *** Added forgotten munmap +void check_mfd_has_seals(const char *file, const int lineno, int fd, int seals) +{ +int ret =SAFE_FCNTL ((fd),F_GET_SEALS ); +if (ret != seals) { +tst_brk_ (file, lineno,TFAIL , +"fd %d doesn't have expected seals (%d expected %d)" , + fd, ret, seals); + } + +tst_res_ (file, lineno,TPASS , +"fd %d has expected seals (%d)" , fd, seals); +}*** Changed this macro for a function and make it print the values of seals
void check_mprotect(const char *file, const int lineno, void *addr,
testcases/kernel/syscalls/memfd_create/memfd_create_common.c +1
-1size_t length, int prot) {@@ -297,7 +312,7 @@ void check_mfd_writeable(const char *filename, const int lineno, int fd)/* verify write() succeeds */ safe_write (filename, lineno,NULL ,1 , fd,"\0\0\0\0" ,4 );tst_res_ (filename, lineno,TPASS ,"write(%d, %s, %d) succeeded" , fd, -"\0\0\0\0" ,4 ); +"\\0\\0\\0\\0" ,4 ); ** Changed this to print literal '\0\0\0\0' instead of random pointertestcases/kernel/syscalls/memfd_create/memfd_create_common.c +0
-0/* verify PROT_READ | PROT_WRITE is allowed */ p = check_mmap(filename, lineno, NULL, MFD_DEF_SIZE,testcases/kernel/syscalls/memfd_create/memfd_create_common.h +4
-8@@ -43,13 +43,7 @@ check_munmap(__FILE__, __LINE__, (p), (length))#define CHECK_MFD_HAS_SEALS (fd, seals) \ - do { \ - if (SAFE_FCNTL((fd), F_GET_SEALS) != (seals)) { \ - tst_brk(TFAIL, "fd %d doesn't have expected seals", \ - (fd)); \ - } \ - tst_res(TPASS, "fd %d has expected seals", (fd)); \ - } while (0) + check_mfd_has_seals(__FILE__, __LINE__, (fd), (seals));#define CHECK_MFD_ADD_SEALS (fd, seals) \ ({int r = SAFE_FCNTL((fd), F_ADD_SEALS, (seals)); \@@ -92,7 +86,7 @@#define CHECK_MFD_GROWABLE_BY_WRITE (fd) \ check_mfd_growable_by_write(__FILE__, __LINE__, (fd)) -#define CHECK_NON_GROWABLE_BY_WRITE (fd) \ +#define CHECK_MFD_NON_GROWABLE_BY_WRITE (fd) \ check_mfd_non_growable_by_write(__FILE__, __LINE__, (fd))void assert_have_memfd_create (const char *filename,const int lineno);@@ -119,6 +113,8 @@ void check_mmap_fail(const char *file, const int lineno, void *addr,void check_munmap (const char *file,const int lineno,void *p,size_t length); +void check_mfd_has_seals (const char *file,const int lineno,int fd,int seals); +void check_mprotect (const char *file,const int lineno,void *addr,size_t length,int prot);
Signature · 2 lines
Regards,
JakubPATCH v5 5/6 syscalls: added memfd_create dir and memfd_create/memfd_create01.c
In reply to Cyril Hrubis----- Original Message -----
Quoted 3 lines
Hi!
Patchset pushed with cosmetic chnages to this patch (see diff below), thanks.
Hi,
build on distro that doesn't define HAVE_FALLOCATE is now failing for me:
# git describe 20170116-207-g16f4d56
# ./configure && make ... gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -Wold-style-definition -D_FORTIFY_SOURCE=2 -I/root/ltp/testcases/kernel/include -I../../../../include -I../../../../include -I../../../../include/old/ -c -o memfd_create01.o memfd_create01.c gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -Wold-style-definition -D_FORTIFY_SOURCE=2 -I/root/ltp/testcases/kernel/include -I../../../../include -I../../../../include -I../../../../include/old/ -c -o memfd_create_common.o memfd_create_common.c In file included from memfd_create_common.c:21: ../../../../include/lapi/fallocate.h: In function ‘fallocate’: ../../../../include/lapi/fallocate.h:55: warning: implicit declaration of function ‘syscall’ ../../../../include/lapi/fallocate.h:55: warning: implicit declaration of function ‘tst_brkm’ ../../../../include/lapi/fallocate.h:55: error: ‘TCONF’ undeclared (first use in this function) ../../../../include/lapi/fallocate.h:55: error: (Each undeclared identifier is reported only once ../../../../include/lapi/fallocate.h:55: error: for each function it appears in.) In file included from memfd_create_common.c:28: /usr/include/unistd.h: At top level: /usr/include/unistd.h:1011: error: conflicting types for ‘syscall’ ../../../../include/lapi/fallocate.h:55: error: previous implicit declaration of ‘syscall’ was here make[4]: *** [memfd_create_common.o] Error 1 make[4]: Leaving directory `/root/ltp/testcases/kernel/syscalls/memfd_create' make[3]: *** [all] Error 2 make[3]: Leaving directory `/root/ltp/testcases/kernel/syscalls' make[2]: *** [all] Error 2 make[2]: Leaving directory `/root/ltp/testcases/kernel' make[1]: *** [all] Error 2 make[1]: Leaving directory `/root/ltp/testcases' make: *** [testcases-all] Error 2
Regards,
Jan
PATCH v5 5/6 syscalls: added memfd_create dir and memfd_create/memfd_create01.c
Hi!
Quoted 22 lines
build on distro that doesn't define
HAVE_FALLOCATEis now failing for me:# git describe 20170116-207-g16f4d56# ./configure && make ... gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -Wold-style-definition -D_FORTIFY_SOURCE=2 -I/root/ltp/testcases/kernel/include -I../../../../include -I../../../../include -I../../../../include/old/ -c -o memfd_create01.o memfd_create01.c gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -Wold-style-definition -D_FORTIFY_SOURCE=2 -I/root/ltp/testcases/kernel/include -I../../../../include -I../../../../include -I../../../../include/old/ -c -o memfd_create_common.o memfd_create_common.c In file included from memfd_create_common.c:21: ../../../../include/lapi/fallocate.h: In function ???fallocate???: ../../../../include/lapi/fallocate.h:55: warning: implicit declaration of function ???syscall??? ../../../../include/lapi/fallocate.h:55: warning: implicit declaration of function ???tst_brkm??? ../../../../include/lapi/fallocate.h:55: error: ???TCONF??? undeclared (first use in this function) ../../../../include/lapi/fallocate.h:55: error: (Each undeclared identifier is reported only once ../../../../include/lapi/fallocate.h:55: error: for each function it appears in.) In file included from memfd_create_common.c:28: /usr/include/unistd.h: At top level: /usr/include/unistd.h:1011: error: conflicting types for ???syscall??? ../../../../include/lapi/fallocate.h:55: error: previous implicit declaration of ???syscall??? was here make[4]: *** [memfd_create_common.o] Error 1
Quoted 8 lines
make[4]: Leaving directory `/root/ltp/testcases/kernel/syscalls/memfd_create' make[3]: *** [all] Error 2 make[3]: Leaving directory `/root/ltp/testcases/kernel/syscalls' make[2]: *** [all] Error 2 make[2]: Leaving directory `/root/ltp/testcases/kernel' make[1]: *** [all] Error 2 make[1]: Leaving directory `/root/ltp/testcases' make: *** [testcases-all] Error 2
Ah, right looks like we have the old API/new API mixed again. Sorry I should have caught that during the review.
Now easy fix would be switching on newlib/oldlib and tst_syscall()/ltp_syscall(). Bit better one would be to rewrite the fallocate tests to newlib and switch to tst_sycall() in the fallocate.h header.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/1 syscalls/memfd_create: Fix build fail when HAVE_FALLOCATE not defined
--- include/lapi/fallocate.h | 12 ++++++++++++ testcases/kernel/syscalls/memfd_create/memfd_create_common.c | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-)
include/lapi/fallocate.h +12 -0
@@ -52,13 +52,25 @@ static inline long fallocate(int fd, int mode, loff_t offset, loff_t len) {/* Deal with 32bit ABIs that have 64bit syscalls. */ # if LTP_USE_64_ABI +#ifdef __TEST_H__return ltp_syscall (__NR_fallocate, fd, mode, offset, len); +#else +return tst_syscall (__NR_fallocate, fd, mode, offset, len); +#endif /* __TEST_H__ */ # else +#ifdef __TEST_H__return (long )ltp_syscall (__NR_fallocate, fd, mode,__LONG_LONG_PAIR ((off_t) (offset >>32 ), (off_t ) offset),__LONG_LONG_PAIR ((off_t) (len >>32 ), (off_t ) len)); +#else +return (long )tst_syscall (__NR_fallocate, fd, mode, +__LONG_LONG_PAIR ((off_t) (offset >>32 ), + (off_t ) offset), +__LONG_LONG_PAIR ((off_t) (len >>32 ), + (off_t ) len)); +#endif /* __TEST_H__ */ # endif }#endif
testcases/kernel/syscalls/memfd_create/memfd_create_common.c +2 -2
@@ -18,7 +18,6 @@#include <sys/types.h> #include <sys/syscall.h> #include <sys/uio.h> -#include <lapi/fallocate.h> #include <lapi/fcntl.h> #include <lapi/memfd.h> #include <errno.h>
@@ -28,7 +27,8 @@#include <unistd.h> #define TST_NO_DEFAULT_MAIN -#include <tst_test.h> +#include "tst_test.h" +#include "lapi/fallocate.h" #include "linux_syscall_numbers.h"
Signature · 1 line
1.8.4.2
PATCH 1/1 syscalls/memfd_create: Fix build fail when HAVE_FALLOCATE not defined
Hi!
Quoted 11 lines
include/lapi/fallocate.h +5
-0/* Deal with 32bit ABIs that have 64bit syscalls. */ # if LTP_USE_64_ABI +#ifdef __TEST_H__return ltp_syscall (__NR_fallocate, fd, mode, offset, len); +#else +return tst_syscall (__NR_fallocate, fd, mode, offset, len); +#endif /* __TEST_H__ */ # else +#ifdef __TEST_H__ return (long)ltp_syscall(__NR_fallocate, fd, mode, __LONG_LONG_PAIR((off_t) (offset >> 32),
include/lapi/fallocate.h static inline long fallocate(int fd, int mode, loff_t offset, loff_t len) · line 73
Quoted 10 lines
include/lapi/fallocate.h +7
-0(off_t) offset),__LONG_LONG_PAIR ((off_t) (len >>32 ), (off_t) len)); +#else +return (long )tst_syscall (__NR_fallocate, fd, mode, +__LONG_LONG_PAIR ((off_t) (offset >>32 ), + (off_t ) offset), +__LONG_LONG_PAIR ((off_t) (len >>32 ), + (off_t ) len)); +#endif /* __TEST_H__ */
We can spare a bit of the duplication by definign the function name:
...
#ifdef __TEST_H__
# define TST_SYSCALL_WRAPPER ltp_syscall #else # define TST_SYSCALL_WRAPPER tst_syscall #endif
...
return (long)TST_SYSCALL_WRAPPER(__NR_fallocate, fd, mode, __LONG_LONG_PAIR((off_t) (offset >> 32), (off_t) offset), __LONG_LONG_PAIR((off_t) (len >> 32), (off_t) len));
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/1 syscalls/memfd_create: Fix build fail when HAVE_FALLOCATE not defined
Hi!
Quoted 33 lines · Cyril Hrubis
Hi!
Quoted 11 lines
include/lapi/fallocate.h +5
-0/* Deal with 32bit ABIs that have 64bit syscalls. */ # if LTP_USE_64_ABI +#ifdef __TEST_H__return ltp_syscall (__NR_fallocate, fd, mode, offset, len); +#else +return tst_syscall (__NR_fallocate, fd, mode, offset, len); +#endif /* __TEST_H__ */ # else +#ifdef __TEST_H__ return (long)ltp_syscall(__NR_fallocate, fd, mode, __LONG_LONG_PAIR((off_t) (offset >> 32),include/lapi/fallocate.h static inline long fallocate(int fd, int mode, loff_t offset, loff_t len) · line 73
Quoted 10 lines
include/lapi/fallocate.h +7
-0(off_t) offset),__LONG_LONG_PAIR ((off_t) (len >>32 ), (off_t) len)); +#else +return (long )tst_syscall (__NR_fallocate, fd, mode, +__LONG_LONG_PAIR ((off_t) (offset >>32 ), + (off_t ) offset), +__LONG_LONG_PAIR ((off_t) (len >>32 ), + (off_t ) len)); +#endif /* __TEST_H__ */ We can spare a bit of the duplication by definign the function name:
...
#ifdef
__TEST_H__# define TST_SYSCALL_WRAPPER ltp_syscall #else # define TST_SYSCALL_WRAPPER tst_syscall #endif
Quoted 7 lines
...
return (long)TST_SYSCALL_WRAPPER(__NR_fallocate, fd, mode, __LONG_LONG_PAIR((off_t) (offset >> 32), (off_t) offset), __LONG_LONG_PAIR((off_t) (len >> 32), (off_t) len));
Oh, right, thanks a lot...
I will send a V2 soon.
Best Regards,
Guangwen Feng
PATCH v2 1/1 syscalls/memfd_create: Fix build failure when HAVE_FALLOCATE not defined
--- include/lapi/fallocate.h | 11 +++++++++-- testcases/kernel/syscalls/memfd_create/memfd_create_common.c | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-)
include/lapi/fallocate.h +9 -2
@@ -48,13 +48,20 @@#endif #if !defined(HAVE_FALLOCATE ) + +#ifdef __TEST_H__ +# define TST_SYSCALL_WRAPPER ltp_syscall +#else +# define TST_SYSCALL_WRAPPER tst_syscall +#endif /* __TEST_H__ */ +static inline long fallocate (int fd,int mode,loff_t offset,loff_t len) {/* Deal with 32bit ABIs that have 64bit syscalls. */ # if LTP_USE_64_ABI -return ltp_syscall (__NR_fallocate, fd, mode, offset, len); +return TST_SYSCALL_WRAPPER (__NR_fallocate, fd, mode, offset, len);# else - return (long)ltp_syscall(__NR_fallocate, fd, mode, + return (long)TST_SYSCALL_WRAPPER(__NR_fallocate, fd, mode, __LONG_LONG_PAIR((off_t) (offset >> 32), (off_t) offset), __LONG_LONG_PAIR((off_t) (len >> 32),
testcases/kernel/syscalls/memfd_create/memfd_create_common.c +2 -2
@@ -18,7 +18,6 @@#include <sys/types.h> #include <sys/syscall.h> #include <sys/uio.h> -#include <lapi/fallocate.h> #include <lapi/fcntl.h> #include <lapi/memfd.h> #include <errno.h>
@@ -28,7 +27,8 @@#include <unistd.h> #define TST_NO_DEFAULT_MAIN -#include <tst_test.h> +#include "tst_test.h" +#include "lapi/fallocate.h" #include "linux_syscall_numbers.h"
Signature · 1 line
1.8.4.2
PATCH v2 1/1 syscalls/memfd_create: Fix build failure when HAVE_FALLOCATE not defined
----- Original Message -----
Quoted 6 lines
Signed-off-by Guangwen Feng <[email protected]>--- include/lapi/fallocate.h | 11 +++++++++-- testcases/kernel/syscalls/memfd_create/memfd_create_common.c | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-)
ACK, it builds now OK for me.
Regards,
Jan
PATCH v2 1/1 syscalls/memfd_create: Fix build failure when HAVE_FALLOCATE not defined
In reply to Guangwen FengHi!
Pushed with cosmetic changes and ack from Jan, thanks.
Quoted 13 lines
testcases/kernel/syscalls/memfd_create/memfd_create_common.c +0
-1@@ -18,7 +18,6 @@#include <sys/types.h> #include <sys/syscall.h> #include <sys/uio.h> -#include <lapi/fallocate.h> #include <lapi/fcntl.h> #include <lapi/memfd.h> #include <errno.h>
testcases/kernel/syscalls/memfd_create/memfd_create_common.c line 31
Quoted 6 lines
testcases/kernel/syscalls/memfd_create/memfd_create_common.c +2
-1@@ -28,7 +27,8 @@#include <unistd.h> #define TST_NO_DEFAULT_MAIN -#include <tst_test.h> +#include "tst_test.h" +#include "lapi/fallocate.h"
I've moved the rest of the lapi headers down here so they stay grouped toghether.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v5 6/6 syscalls/memfd_create02.c: added new test
In reply to Jakub Racek--- runtest/syscalls | 1 + testcases/kernel/syscalls/.gitignore | 1 + .../kernel/syscalls/memfd_create/memfd_create02.c | 94 ++++++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 testcases/kernel/syscalls/memfd_create/memfd_create02.c
runtest/syscalls +1 -0
@@ -1452,3 +1452,4 @@ futex_wait_bitset01 futex_wait_bitset01 futex_wait_bitset02 futex_wait_bitset02 memfd_create01 memfd_create01 +memfd_create02 memfd_create02
testcases/kernel/syscalls/.gitignore +1 -0
@@ -1119,3 +1119,4 @@ /perf_event_open/perf_event_open01 /perf_event_open/perf_event_open02 /memfd_create/memfd_create01 +/memfd_create/memfd_create02
testcases/kernel/syscalls/memfd_create/memfd_create02.c new file +94 -0
94 lines not on this page · raw message
Signature · 1 line
1.8.3.1