[LTP] [PATCH] lapi/userfaultfd: Handle ENOSYS in SAFE_USERFAULTFD

Wake Liu wakel@google.com
Wed Apr 29 08:40:10 CEST 2026


When CONFIG_USERFAULTFD is not enabled in the kernel, the userfaultfd
syscall returns ENOSYS. Currently, SAFE_USERFAULTFD calls tst_brk(TBROK)
for any error other than EPERM, causing tests to fail when they should
be skipped.

Add a check for ENOSYS to return TCONF, so that tests using
SAFE_USERFAULTFD are skipped appropriately on kernels without
userfaultfd support.

Signed-off-by: Wake Liu <wakel@google.com>
---
 include/lapi/userfaultfd.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/include/lapi/userfaultfd.h b/include/lapi/userfaultfd.h
index 0c9e34c84..09126d856 100644
--- a/include/lapi/userfaultfd.h
+++ b/include/lapi/userfaultfd.h
@@ -244,6 +244,10 @@ static inline int safe_userfaultfd(const char *file, const int lineno, int
 retry:
 	ret = tst_syscall(__NR_userfaultfd, flags);
 	if (ret == -1) {
+		if (errno == ENOSYS) {
+			tst_brk_(file, lineno, TCONF | TERRNO,
+				"userfaultfd() is not supported by this kernel");
+		}
 		if (errno == EPERM) {
 			if (retry && !(flags & UFFD_USER_MODE_ONLY)) {
 				flags |= UFFD_USER_MODE_ONLY;
-- 
2.54.0.545.g6539524ca2-goog



More information about the ltp mailing list