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 v2 3/7] selftests: kselftest: Add memfd_create syscall compatibility
Date: Tue, 2 Sep 2025 17:01:40 +0000 [thread overview]
Message-ID: <20250902170147.55583-4-aqibaf@amazon.com> (raw)
In-Reply-To: <20250902170147.55583-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 c3f5142b0..a78b64117 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 parent reply other threads:[~2025-09-02 17:03 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20250902170147.55583-1-aqibaf@amazon.com>
2025-09-02 17:01 ` Aqib Faruqui [this message]
2025-09-02 17:01 ` [PATCH v2 4/7] KVM: selftests: Add backtrace fallback 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=20250902170147.55583-4-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