[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250829142556.72577-5-aqibaf@amazon.com>
Date: Fri, 29 Aug 2025 14:25:48 +0000
From: Aqib Faruqui <aqibaf@...zon.com>
To: Shuah Khan <shuah@...nel.org>, Paolo Bonzini <pbonzini@...hat.com>,
<linux-kselftest@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<kvm@...r.kernel.org>
CC: <nh-open-source@...zon.com>, <aqibaf@...zon.com>
Subject: [PATCH 4/9] selftests: kselftest: Add memfd_create syscall compatibility
The memfd_create function and related MFD_* flags may not be available
in non-glibc C libraries. Some selftests use memfd_create for
memory backing operations.
Add fallback definitions for MFD_CLOEXEC and MFD_HUGETLB flags, and
provide a memfd_create wrapper.
Signed-off-by: Aqib Faruqui <aqibaf@...zon.com>
---
tools/testing/selftests/kselftest.h | 19 +++++++++++++++++++
tools/testing/selftests/kvm/lib/kvm_util.c | 1 +
2 files changed, 20 insertions(+)
diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h
index c3b6d2604..f362c6766 100644
--- a/tools/testing/selftests/kselftest.h
+++ b/tools/testing/selftests/kselftest.h
@@ -57,6 +57,7 @@
#include <string.h>
#include <stdio.h>
#include <sys/utsname.h>
+#include <sys/syscall.h>
#endif
#ifndef ARRAY_SIZE
@@ -80,6 +81,24 @@
#endif
#endif /* end arch */
+#ifndef MFD_CLOEXEC
+#define MFD_CLOEXEC 0x0001U
+#endif
+
+#ifndef MFD_HUGETLB
+#define MFD_HUGETLB 0x0004U
+#endif
+
+static inline int memfd_create(const char *name, unsigned int flags)
+{
+#ifdef __NR_memfd_create
+ return syscall(__NR_memfd_create, name, flags);
+#else
+ errno = ENOSYS;
+ return -1;
+#endif
+}
+
/* define kselftest exit codes */
#define KSFT_PASS 0
#define KSFT_FAIL 1
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index 5ce80303d..cb5209f6a 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -15,6 +15,7 @@
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/syscall.h>
#include <unistd.h>
#include <linux/kernel.h>
--
2.47.3
Powered by blists - more mailing lists