public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 3/7] selftests: kselftest: Add memfd_create syscall compatibility
       [not found] <20250902170147.55583-1-aqibaf@amazon.com>
@ 2025-09-02 17:01 ` Aqib Faruqui
  2025-09-02 17:01 ` [PATCH v2 4/7] KVM: selftests: Add backtrace fallback Aqib Faruqui
  1 sibling, 0 replies; 2+ messages in thread
From: Aqib Faruqui @ 2025-09-02 17:01 UTC (permalink / raw)
  To: Shuah Khan, Paolo Bonzini, linux-kselftest, linux-kernel, kvm
  Cc: nh-open-source, aqibaf

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH v2 4/7] KVM: selftests: Add backtrace fallback
       [not found] <20250902170147.55583-1-aqibaf@amazon.com>
  2025-09-02 17:01 ` [PATCH v2 3/7] selftests: kselftest: Add memfd_create syscall compatibility Aqib Faruqui
@ 2025-09-02 17:01 ` Aqib Faruqui
  1 sibling, 0 replies; 2+ messages in thread
From: Aqib Faruqui @ 2025-09-02 17:01 UTC (permalink / raw)
  To: Paolo Bonzini, Shuah Khan, kvm, linux-kselftest, linux-kernel
  Cc: nh-open-source, aqibaf

The backtrace() function is a GNU extension available in glibc but may
not be present in non-glibc libraries. KVM selftests use backtrace() for
error reporting and debugging.

Add conditional inclusion of execinfo.h only for glibc builds and
provide a weak stub implementation of backtrace() that returns 0 (stack
trace empty) for non-glibc systems.

Signed-off-by: Aqib Faruqui <aqibaf@amazon.com>
---
 tools/testing/selftests/kvm/lib/assert.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/kvm/lib/assert.c b/tools/testing/selftests/kvm/lib/assert.c
index b49690658..c9778dc6c 100644
--- a/tools/testing/selftests/kvm/lib/assert.c
+++ b/tools/testing/selftests/kvm/lib/assert.c
@@ -6,11 +6,19 @@
  */
 #include "test_util.h"
 
-#include <execinfo.h>
 #include <sys/syscall.h>
 
+#ifdef __GLIBC__
+#include <execinfo.h> /* backtrace */
+#endif
+
 #include "kselftest.h"
 
+int __attribute__((weak)) backtrace(void **buffer, int size)
+{
+	return 0;
+}
+
 /* Dumps the current stack trace to stderr. */
 static void __attribute__((noinline)) test_dump_stack(void);
 static void test_dump_stack(void)
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-09-02 17:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20250902170147.55583-1-aqibaf@amazon.com>
2025-09-02 17:01 ` [PATCH v2 3/7] selftests: kselftest: Add memfd_create syscall compatibility Aqib Faruqui
2025-09-02 17:01 ` [PATCH v2 4/7] KVM: selftests: Add backtrace fallback Aqib Faruqui

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox