From: Aqib Faruqui <aqibaf@amazon.com>
To: Shuah Khan <shuah@kernel.org>,
Paolo Bonzini <pbonzini@redhat.com>,
<linux-kselftest@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<kvm@vger.kernel.org>
Cc: <nh-open-source@amazon.com>, <aqibaf@amazon.com>
Subject: [PATCH 4/9] selftests: kselftest: Add memfd_create syscall compatibility
Date: Fri, 29 Aug 2025 14:25:48 +0000 [thread overview]
Message-ID: <20250829142556.72577-5-aqibaf@amazon.com> (raw)
In-Reply-To: <20250829142556.72577-1-aqibaf@amazon.com>
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@amazon.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
next prev parent reply other threads:[~2025-08-29 14:28 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-29 14:25 [PATCH 0/9] Add compatibility fixes for KVM selftests with non-glibc C libraries Aqib Faruqui
2025-08-29 14:25 ` [PATCH 1/9] KVM: selftests: Add pidfd_open syscall number fallback Aqib Faruqui
2025-08-29 22:52 ` Sean Christopherson
2025-08-29 14:25 ` [PATCH 2/9] KVM: selftests: Add __packed attribute fallback Aqib Faruqui
2025-08-29 22:46 ` Sean Christopherson
2025-09-01 15:08 ` Faruqui, Aqib
2025-08-29 14:25 ` [PATCH 3/9] KVM: selftests: Add pthread_attr_setaffinity_np fallback Aqib Faruqui
2025-08-29 22:37 ` Sean Christopherson
2025-08-29 14:25 ` Aqib Faruqui [this message]
2025-08-29 14:25 ` [PATCH 5/9] KVM: selftests: Prevent PAGE_SIZE redefinition on x86 Aqib Faruqui
2025-08-29 20:38 ` Sean Christopherson
[not found] ` <33701547-13AA-467D-AC41-A1A05963B1DD@amazon.com>
2025-09-05 8:39 ` Sean Christopherson
2025-09-05 13:59 ` Aqib Faruqui
2025-09-08 18:22 ` Sean Christopherson
2025-08-29 14:25 ` [PATCH 6/9] KVM: selftests: Add backtrace fallback Aqib Faruqui
2025-08-29 14:25 ` [PATCH 7/9] rseq: selftests: Add non-glibc compatibility fixes Aqib Faruqui
2025-08-29 14:25 ` [PATCH 8/9] selftests: Fix stdbuf compatibility in mixed libc environments Aqib Faruqui
2025-08-29 14:25 ` [PATCH 9/9] selftests: kselftest: Add ulong typedef for non-glibc compatibility Aqib Faruqui
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250829142556.72577-5-aqibaf@amazon.com \
--to=aqibaf@amazon.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=nh-open-source@amazon.com \
--cc=pbonzini@redhat.com \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®