Skip to contentSkip to conversation

memfd_create: move sys_memfd_create() to lapi/memfd.h

PATCH Applied Ricardo Branco 4 participants 8 messages May 7 – Jun 11

lore
Share & tools
lore
#0 lore raw

PATCH v7 1/2 memfd_create: move sys_memfd_create() to lapi/memfd.h

Add the static inline wrapper to include/lapi/memfd.h and include the required headers so other tests can reuse it.

Also fix some minor issues detected by make check.

---
 include/lapi/memfd.h                                      | 8 ++++++++
 testcases/kernel/syscalls/memfd_create/memfd_create01.c   | 1 -
 .../kernel/syscalls/memfd_create/memfd_create_common.c    | 5 -----
 .../kernel/syscalls/memfd_create/memfd_create_common.h    | 4 +---
 4 files changed, 9 insertions(+), 9 deletions(-)
include/lapi/memfd.h +8 -0
index 57b6cd83d..46ccb0a3f 100644
@@ -6,6 +6,9 @@
 #ifndef LAPI_MEMFD_H__
 #define LAPI_MEMFD_H__
 
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+
 /* flags for memfd_create(2) (unsigned int) */
 #ifndef MFD_CLOEXEC
 # define MFD_CLOEXEC             0x0001U
@@ -47,4 +50,9 @@
 #define MFD_HUGE_16GB (34 << 26)
 #endif
 
+static inline int sys_memfd_create(const char *name, unsigned int flags)
+{
+	return tst_syscall(__NR_memfd_create, name, flags);
+}
+
 #endif /* LAPI_MEMFD_H__ */
testcases/kernel/syscalls/memfd_create/memfd_create01.c +0 -1
index 73f6b01e8..28ad04a86 100644
@@ -212,7 +212,6 @@ static void test_share_open(int fd)
 	SAFE_CLOSE(fd2);
 }
 
-
 static const struct tcase {
 	int flags;
 	void (*func)(int fd);
testcases/kernel/syscalls/memfd_create/memfd_create_common.c +0 -5
index a52b02a56..63e8daac5 100644
@@ -24,11 +24,6 @@
 
 #include "memfd_create_common.h"
 
-int sys_memfd_create(const char *name, unsigned int flags)
-{
-	return tst_syscall(__NR_memfd_create, name, flags);
-}
-
 int check_fallocate(const char *filename, const int lineno, int fd,
 			int mode, off_t offset, off_t len)
 {
testcases/kernel/syscalls/memfd_create/memfd_create_common.h +1 -3
index 60ad895fe..df809d6c7 100644
@@ -50,7 +50,7 @@
 	check_munmap(__FILE__, __LINE__, (p), (length))
 
 #define CHECK_MFD_HAS_SEALS(fd, seals) \
-	check_mfd_has_seals(__FILE__, __LINE__, (fd), (seals));
+	check_mfd_has_seals(__FILE__, __LINE__, (fd), (seals))
 
 #define CHECK_MFD_ADD_SEALS(fd, seals) \
 	({int r = SAFE_FCNTL((fd), F_ADD_SEALS, (seals)); \
@@ -101,8 +101,6 @@ int mfd_flags_available(const char *filename, const int lineno,
 
 int get_mfd_all_available_flags(const char *filename, const int lineno);
 
-int sys_memfd_create(const char *name, unsigned int flags);
-
 int check_fallocate(const char *filename, const int lineno, int fd,
 			int mode, off_t offset, off_t len);
 int check_fallocate_fail(const char *filename, const int lineno, int fd,
Signature · 5 lines
2.54.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

PATCH v7 2/2 userfaultfd: Add new test using UFFDIO_CONTINUE

Add test to exercise UFFDIO_CONTINUE on a shared-memory mapping with UFFD_PAGEFAULT_FLAG_MINOR. The test populates a memfd-backed page, drops only the PTEs with MADV_DONTNEED, verifies that the resulting fault is reported as MINOR, updates the page cache from the handler thread, and resumes execution with UFFDIO_CONTINUE.

---
 include/lapi/userfaultfd.h                    |   1 +
 runtest/syscalls                              |   1 +
 .../kernel/syscalls/userfaultfd/.gitignore    |   1 +
 .../kernel/syscalls/userfaultfd/Makefile      |   1 +
 .../syscalls/userfaultfd/userfaultfd07.c      | 155 ++++++++++++++++++
 5 files changed, 159 insertions(+)
 create mode 100644 testcases/kernel/syscalls/userfaultfd/userfaultfd07.c
include/lapi/userfaultfd.h +1 -0
index 170dfadd4..4a25e7338 100644
@@ -171,6 +171,7 @@ struct uffdio_zeropage {
 #ifndef UFFD_PAGEFAULT_FLAG_MINOR
 #define UFFD_FEATURE_MINOR_HUGETLBFS		(1<<9)
 #define UFFDIO_REGISTER_MODE_MINOR	((__u64)1<<2)
+#define UFFD_PAGEFAULT_FLAG_MINOR	(1<<2)
 
 #define _UFFDIO_CONTINUE		(0x07)
 #define UFFDIO_CONTINUE		_IOWR(UFFDIO, _UFFDIO_CONTINUE,	\
runtest/syscalls +1 -0
index f790e8f84..9fea02cd8 100644
@@ -1784,6 +1784,7 @@ userfaultfd03 userfaultfd03
 userfaultfd04 userfaultfd04
 userfaultfd05 userfaultfd05
 userfaultfd06 userfaultfd06
+userfaultfd07 userfaultfd07
 
 ustat01 ustat01
 ustat02 ustat02
testcases/kernel/syscalls/userfaultfd/.gitignore +1 -0
index bc32fdf3b..3478a162e 100644
@@ -4,3 +4,4 @@
 /userfaultfd04
 /userfaultfd05
 /userfaultfd06
+/userfaultfd07
testcases/kernel/syscalls/userfaultfd/Makefile +1 -0
index 3252e47df..257249e88 100644
@@ -17,3 +17,4 @@ userfaultfd03: CFLAGS += -pthread
 userfaultfd04: CFLAGS += -pthread
 userfaultfd05: CFLAGS += -pthread
 userfaultfd06: CFLAGS += -pthread
+userfaultfd07: CFLAGS += -pthread
testcases/kernel/syscalls/userfaultfd/userfaultfd07.c new file +155 -0

155 lines not on this page · raw message

Signature · 5 lines
2.54.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw
In reply to Ricardo Branco

Hi Ricardo,

--- [PATCH 1/2] ---

Quoted 6 lines · Ricardo Branco

memfd_create: move sys_memfd_create() to lapi/memfd.h

Add the static inline wrapper to include/lapi/memfd.h and include the required headers so other tests can reuse it.

Also fix some minor issues detected by make check.

The "also fix" indicates a second logical change bundled in. Please split the minor cleanup fixes (blank line in memfd_create01.c, trailing semicolon in CHECK_MFD_HAS_SEALS) into a separate commit so each patch contains exactly one logical change.

testcases/kernel/syscalls/memfd_create/memfd_create_common.h line 53

Quoted 2 lines
testcases/kernel/syscalls/memfd_create/memfd_create_common.h +1 -1
-	check_mfd_has_seals(__FILE__, __LINE__, (fd), (seals));
+	check_mfd_has_seals(__FILE__, __LINE__, (fd), (seals))

This fix is independent of the sys_memfd_create() move — separate commit.

Pre-existing issues noticed in the surrounding code (not introduced by this patch):

- include/lapi/memfd.h (pre-patch) — file relied on callers to pull in tst_test.h and lapi/syscalls.h transitively; now correctly self-contained.

---
Note:

Our agent completed the review of the patch. The full review can be found at: https://github.com/linux-test-project/ltp-agent/actions/runs/25514269891

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw
In reply to Ricardo Branco

Hi!

Quoted 6 lines

Add the static inline wrapper to include/lapi/memfd.h and include the required headers so other tests can reuse it.

Also fix some minor issues detected by make check.

You already got my Reviewed-by: for this patch you should have added it here in this version.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp