* [PATCH liburing 0/3] Bring back `CONFIG_HAVE_MEMFD_CREATE` to fix Android build error
@ 2025-07-15 5:06 Alviro Iskandar Setiawan
2025-07-15 5:06 ` [PATCH liburing 1/3] Revert "test/io_uring_register: kill old memfd test" Alviro Iskandar Setiawan
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Alviro Iskandar Setiawan @ 2025-07-15 5:06 UTC (permalink / raw)
To: Jens Axboe
Cc: Alviro Iskandar Setiawan, Linux Kernel Mailing List,
io-uring Mailing List, GNU/Weeb Mailing List, Ammar Faizi
Hello,
There are three patches in this series to address Android build
error related to `memfd_create()`. The changes are as follows:
1) Bring back `CONFIG_HAVE_MEMFD_CREATE` and the associated memfd test
to resolve Android build failures caused by:
93d3a7a70b4a ("examples/zcrx: udmabuf backed areas")
It added a call to `memfd_create()`, which is unavailable on some
Android toolchains, leading to the following build error:
```
zcrx.c:111:10: error: call to undeclared function 'memfd_create'; ISO C99 and \
later do not support implicit function declarations \
[-Wimplicit-function-declaration]
111 | memfd = memfd_create("udmabuf-test", MFD_ALLOW_SEALING);
| ^
```
This reversion is a preparation step for a proper fix by ensuring
`memfd_create()` usage is guarded and portable. Issue #620 was
initially unclear, but we now suspect it stemmed from improper
compiler/linker flag combinations.
2) In test dir, relocate `memfd_create()` to helpers.c for broader
test access. Previously, the static definition of `memfd_create()` was
limited to io_uring_register.c. Now, promote it to a shared location
accessible to all test cases, ensuring that future tests using
`memfd_create()` do not trigger build failures on Android targets where
the syscall is undefined in the standard headers. It improves
portability and prevents regressions across test builds.
3) Last, in example dir, add `memfd_create()` helper to fix the
build error in zcrx example.
Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
Signed-off-by: Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>
---
Alviro Iskandar Setiawan (3):
Revert "test/io_uring_register: kill old memfd test"
test: Move `memfd_create()` to helpers.c, make it accessible for all tests
examples: Add `memfd_create()` helper
configure | 19 +++++++
examples/helpers.c | 8 +++
examples/helpers.h | 5 ++
test/helpers.c | 8 +++
test/helpers.h | 5 ++
test/io_uring_register.c | 108 +++++++++++++++++++++++++++++++++++++++
6 files changed, 153 insertions(+)
base-commit: 0272bfa96f02cc47c024ec510a764ef7e37b76bf
--
Alviro Iskandar Setiawan
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH liburing 1/3] Revert "test/io_uring_register: kill old memfd test"
2025-07-15 5:06 [PATCH liburing 0/3] Bring back `CONFIG_HAVE_MEMFD_CREATE` to fix Android build error Alviro Iskandar Setiawan
@ 2025-07-15 5:06 ` Alviro Iskandar Setiawan
2025-07-15 14:10 ` Jens Axboe
2025-07-15 5:06 ` [PATCH liburing 2/3] test: Move `memfd_create()` to helpers.c, make it accessible for all tests Alviro Iskandar Setiawan
2025-07-15 5:06 ` [PATCH liburing 3/3] examples: Add `memfd_create()` helper Alviro Iskandar Setiawan
2 siblings, 1 reply; 6+ messages in thread
From: Alviro Iskandar Setiawan @ 2025-07-15 5:06 UTC (permalink / raw)
To: Jens Axboe
Cc: Alviro Iskandar Setiawan, Linux Kernel Mailing List,
io-uring Mailing List, GNU/Weeb Mailing List, Ammar Faizi
This reverts commit 732bf609b670631731765a585a68d14ed3fdc9b7.
Bring back `CONFIG_HAVE_MEMFD_CREATE` and the associated memfd test
to resolve Android build failures caused by:
93d3a7a70b4a ("examples/zcrx: udmabuf backed areas")
It added a call to `memfd_create()`, which is unavailable on some
Android toolchains, leading to the following build error:
```
zcrx.c:111:10: error: call to undeclared function 'memfd_create'; ISO C99 and \
later do not support implicit function declarations \
[-Wimplicit-function-declaration]
111 | memfd = memfd_create("udmabuf-test", MFD_ALLOW_SEALING);
| ^
```
This reversion is a preparation step for a proper fix by ensuring
`memfd_create()` usage is guarded and portable. Issue #620 was
initially unclear, but we now suspect it stemmed from improper
compiler/linker flag combinations.
Co-authored-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
Signed-off-by: Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>
---
configure | 19 +++++++
test/io_uring_register.c | 119 +++++++++++++++++++++++++++++++++++++++
2 files changed, 138 insertions(+)
diff --git a/configure b/configure
index 552f8ae..3c95214 100755
--- a/configure
+++ b/configure
@@ -379,6 +379,22 @@ if compile_prog "" "" "has_ucontext"; then
fi
print_config "has_ucontext" "$has_ucontext"
+##########################################
+# check for memfd_create(2)
+has_memfd_create="no"
+cat > $TMPC << EOF
+#include <sys/mman.h>
+int main(int argc, char **argv)
+{
+ int memfd = memfd_create("test", 0);
+ return 0;
+}
+EOF
+if compile_prog "-Werror=implicit-function-declaration" "" "has_memfd_create"; then
+ has_memfd_create="yes"
+fi
+print_config "has_memfd_create" "$has_memfd_create"
+
##########################################
# Check NVME_URING_CMD support
nvme_uring_cmd="no"
@@ -539,6 +555,9 @@ fi
if test "$array_bounds" = "yes"; then
output_sym "CONFIG_HAVE_ARRAY_BOUNDS"
fi
+if test "$has_memfd_create" = "yes"; then
+ output_sym "CONFIG_HAVE_MEMFD_CREATE"
+fi
if test "$nvme_uring_cmd" = "yes"; then
output_sym "CONFIG_HAVE_NVME_URING"
fi
diff --git a/test/io_uring_register.c b/test/io_uring_register.c
index b53a67d..f08f0ca 100644
--- a/test/io_uring_register.c
+++ b/test/io_uring_register.c
@@ -32,6 +32,17 @@ static int pagesize;
static rlim_t mlock_limit;
static int devnull;
+#if !defined(CONFIG_HAVE_MEMFD_CREATE)
+#include <sys/syscall.h>
+#include <linux/memfd.h>
+
+static int memfd_create(const char *name, unsigned int flags)
+{
+ return (int)syscall(SYS_memfd_create, name, flags);
+}
+#endif
+
+
static int expect_fail(int fd, unsigned int opcode, void *arg,
unsigned int nr_args, int error, int error2)
{
@@ -466,6 +477,113 @@ static int __test_poll_ringfd(int ring_flags)
return status;
}
+static int test_shmem(void)
+{
+ const char pattern = 0xEA;
+ const int len = 4096;
+ struct io_uring_sqe *sqe;
+ struct io_uring_cqe *cqe;
+ struct io_uring ring;
+ struct iovec iov;
+ int memfd, ret, i;
+ char *mem;
+ int pipefd[2] = {-1, -1};
+
+ ret = io_uring_queue_init(8, &ring, 0);
+ if (ret)
+ return 1;
+
+ if (pipe(pipefd)) {
+ perror("pipe");
+ return 1;
+ }
+ memfd = memfd_create("uring-shmem-test", 0);
+ if (memfd < 0) {
+ fprintf(stderr, "memfd_create() failed %i\n", -errno);
+ return 1;
+ }
+ if (ftruncate(memfd, len)) {
+ fprintf(stderr, "can't truncate memfd\n");
+ return 1;
+ }
+ mem = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, memfd, 0);
+ if (!mem) {
+ fprintf(stderr, "mmap failed\n");
+ return 1;
+ }
+ for (i = 0; i < len; i++)
+ mem[i] = pattern;
+
+ iov.iov_base = mem;
+ iov.iov_len = len;
+ ret = io_uring_register_buffers(&ring, &iov, 1);
+ if (ret) {
+ if (ret == -EOPNOTSUPP) {
+ fprintf(stdout, "memfd registration isn't supported, "
+ "skip\n");
+ goto out;
+ }
+
+ fprintf(stderr, "buffer reg failed: %d\n", ret);
+ return 1;
+ }
+
+ /* check that we can read and write from/to shmem reg buffer */
+ sqe = io_uring_get_sqe(&ring);
+ io_uring_prep_write_fixed(sqe, pipefd[1], mem, 512, 0, 0);
+ sqe->user_data = 1;
+
+ ret = io_uring_submit(&ring);
+ if (ret != 1) {
+ fprintf(stderr, "submit write failed\n");
+ return 1;
+ }
+ ret = io_uring_wait_cqe(&ring, &cqe);
+ if (ret < 0 || cqe->user_data != 1 || cqe->res != 512) {
+ fprintf(stderr, "reading from shmem failed\n");
+ return 1;
+ }
+ io_uring_cqe_seen(&ring, cqe);
+
+ /* clean it, should be populated with the pattern back from the pipe */
+ memset(mem, 0, 512);
+ sqe = io_uring_get_sqe(&ring);
+ io_uring_prep_read_fixed(sqe, pipefd[0], mem, 512, 0, 0);
+ sqe->user_data = 2;
+
+ ret = io_uring_submit(&ring);
+ if (ret != 1) {
+ fprintf(stderr, "submit write failed\n");
+ return 1;
+ }
+ ret = io_uring_wait_cqe(&ring, &cqe);
+ if (ret < 0 || cqe->user_data != 2 || cqe->res != 512) {
+ fprintf(stderr, "reading from shmem failed\n");
+ return 1;
+ }
+ io_uring_cqe_seen(&ring, cqe);
+
+ for (i = 0; i < 512; i++) {
+ if (mem[i] != pattern) {
+ fprintf(stderr, "data integrity fail\n");
+ return 1;
+ }
+ }
+
+ ret = io_uring_unregister_buffers(&ring);
+ if (ret) {
+ fprintf(stderr, "buffer unreg failed: %d\n", ret);
+ return 1;
+ }
+out:
+ io_uring_queue_exit(&ring);
+ close(pipefd[0]);
+ close(pipefd[1]);
+ munmap(mem, len);
+ close(memfd);
+ return 0;
+}
+
static int test_poll_ringfd(void)
{
int ret;
@@ -526,6 +644,7 @@ int main(int argc, char **argv)
/* uring poll on the uring fd */
status |= test_poll_ringfd();
+ status |= test_shmem();
if (status)
fprintf(stderr, "FAIL\n");
--
Alviro Iskandar Setiawan
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH liburing 2/3] test: Move `memfd_create()` to helpers.c, make it accessible for all tests
2025-07-15 5:06 [PATCH liburing 0/3] Bring back `CONFIG_HAVE_MEMFD_CREATE` to fix Android build error Alviro Iskandar Setiawan
2025-07-15 5:06 ` [PATCH liburing 1/3] Revert "test/io_uring_register: kill old memfd test" Alviro Iskandar Setiawan
@ 2025-07-15 5:06 ` Alviro Iskandar Setiawan
2025-07-15 5:06 ` [PATCH liburing 3/3] examples: Add `memfd_create()` helper Alviro Iskandar Setiawan
2 siblings, 0 replies; 6+ messages in thread
From: Alviro Iskandar Setiawan @ 2025-07-15 5:06 UTC (permalink / raw)
To: Jens Axboe
Cc: Alviro Iskandar Setiawan, Linux Kernel Mailing List,
io-uring Mailing List, GNU/Weeb Mailing List, Ammar Faizi
Previously, the static definition of `memfd_create()` was limited to
io_uring_register.c. Now, promote it to a shared location accessible
to all test cases, ensuring that future tests using `memfd_create()`
do not trigger build failures on Android targets where the syscall
is undefined in the standard headers. It improves portability and
prevents regressions across test builds.
Co-authored-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
Signed-off-by: Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>
---
test/helpers.c | 8 ++++++++
test/helpers.h | 5 +++++
test/io_uring_register.c | 11 -----------
3 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/test/helpers.c b/test/helpers.c
index 0589548..f1d4477 100644
--- a/test/helpers.c
+++ b/test/helpers.c
@@ -18,6 +18,14 @@
#include "helpers.h"
#include "liburing.h"
+#ifndef CONFIG_HAVE_MEMFD_CREATE
+#include <sys/syscall.h>
+int memfd_create(const char *name, unsigned int flags)
+{
+ return (int)syscall(SYS_memfd_create, name, flags);
+}
+#endif
+
/*
* Helper for allocating memory in tests.
*/
diff --git a/test/helpers.h b/test/helpers.h
index 3f0c11a..8ab0920 100644
--- a/test/helpers.h
+++ b/test/helpers.h
@@ -122,6 +122,11 @@ unsigned long long mtime_since_now(struct timeval *tv);
unsigned long long utime_since(const struct timeval *s, const struct timeval *e);
unsigned long long utime_since_now(struct timeval *tv);
+#ifndef CONFIG_HAVE_MEMFD_CREATE
+#include <linux/memfd.h>
+#endif
+int memfd_create(const char *name, unsigned int flags);
+
#ifdef __cplusplus
}
#endif
diff --git a/test/io_uring_register.c b/test/io_uring_register.c
index f08f0ca..c36c4d8 100644
--- a/test/io_uring_register.c
+++ b/test/io_uring_register.c
@@ -32,17 +32,6 @@ static int pagesize;
static rlim_t mlock_limit;
static int devnull;
-#if !defined(CONFIG_HAVE_MEMFD_CREATE)
-#include <sys/syscall.h>
-#include <linux/memfd.h>
-
-static int memfd_create(const char *name, unsigned int flags)
-{
- return (int)syscall(SYS_memfd_create, name, flags);
-}
-#endif
-
-
static int expect_fail(int fd, unsigned int opcode, void *arg,
unsigned int nr_args, int error, int error2)
{
--
Alviro Iskandar Setiawan
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH liburing 3/3] examples: Add `memfd_create()` helper
2025-07-15 5:06 [PATCH liburing 0/3] Bring back `CONFIG_HAVE_MEMFD_CREATE` to fix Android build error Alviro Iskandar Setiawan
2025-07-15 5:06 ` [PATCH liburing 1/3] Revert "test/io_uring_register: kill old memfd test" Alviro Iskandar Setiawan
2025-07-15 5:06 ` [PATCH liburing 2/3] test: Move `memfd_create()` to helpers.c, make it accessible for all tests Alviro Iskandar Setiawan
@ 2025-07-15 5:06 ` Alviro Iskandar Setiawan
2 siblings, 0 replies; 6+ messages in thread
From: Alviro Iskandar Setiawan @ 2025-07-15 5:06 UTC (permalink / raw)
To: Jens Axboe
Cc: Alviro Iskandar Setiawan, Linux Kernel Mailing List,
io-uring Mailing List, GNU/Weeb Mailing List, Ammar Faizi
Add `memfd_create()` helper to handle missing defintion on an environment
where `CONFIG_HAVE_MEMFD_CREATE` is not defined.
Co-authored-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
Signed-off-by: Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>
---
examples/helpers.c | 8 ++++++++
examples/helpers.h | 5 +++++
2 files changed, 13 insertions(+)
diff --git a/examples/helpers.c b/examples/helpers.c
index 483ddee..8c112f1 100644
--- a/examples/helpers.c
+++ b/examples/helpers.c
@@ -13,6 +13,14 @@
#include "helpers.h"
+#ifndef CONFIG_HAVE_MEMFD_CREATE
+#include <sys/syscall.h>
+int memfd_create(const char *name, unsigned int flags)
+{
+ return (int)syscall(SYS_memfd_create, name, flags);
+}
+#endif
+
int setup_listening_socket(int port, int ipv6)
{
struct sockaddr_in srv_addr = { };
diff --git a/examples/helpers.h b/examples/helpers.h
index 44543e1..0b6f15f 100644
--- a/examples/helpers.h
+++ b/examples/helpers.h
@@ -17,4 +17,9 @@ void *t_aligned_alloc(size_t alignment, size_t size);
void t_error(int status, int errnum, const char *format, ...);
+#ifndef CONFIG_HAVE_MEMFD_CREATE
+#include <linux/memfd.h>
+#endif
+int memfd_create(const char *name, unsigned int flags);
+
#endif
--
Alviro Iskandar Setiawan
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH liburing 1/3] Revert "test/io_uring_register: kill old memfd test"
2025-07-15 5:06 ` [PATCH liburing 1/3] Revert "test/io_uring_register: kill old memfd test" Alviro Iskandar Setiawan
@ 2025-07-15 14:10 ` Jens Axboe
2025-07-16 0:03 ` Alviro Iskandar Setiawan
0 siblings, 1 reply; 6+ messages in thread
From: Jens Axboe @ 2025-07-15 14:10 UTC (permalink / raw)
To: Alviro Iskandar Setiawan
Cc: Linux Kernel Mailing List, io-uring Mailing List,
GNU/Weeb Mailing List, Ammar Faizi
On 7/14/25 11:06 PM, Alviro Iskandar Setiawan wrote:
> This reverts commit 732bf609b670631731765a585a68d14ed3fdc9b7.
>
> Bring back `CONFIG_HAVE_MEMFD_CREATE` and the associated memfd test
> to resolve Android build failures caused by:
>
> 93d3a7a70b4a ("examples/zcrx: udmabuf backed areas")
>
> It added a call to `memfd_create()`, which is unavailable on some
> Android toolchains, leading to the following build error:
>
> ```
> zcrx.c:111:10: error: call to undeclared function 'memfd_create'; ISO C99 and \
> later do not support implicit function declarations \
> [-Wimplicit-function-declaration]
> 111 | memfd = memfd_create("udmabuf-test", MFD_ALLOW_SEALING);
> | ^
> ```
>
> This reversion is a preparation step for a proper fix by ensuring
> `memfd_create()` usage is guarded and portable. Issue #620 was
> initially unclear, but we now suspect it stemmed from improper
> compiler/linker flag combinations.
Maybe just bring back the configure parts? The test, as mentioned in
that commit, is pretty useless.
--
Jens Axboe
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH liburing 1/3] Revert "test/io_uring_register: kill old memfd test"
2025-07-15 14:10 ` Jens Axboe
@ 2025-07-16 0:03 ` Alviro Iskandar Setiawan
0 siblings, 0 replies; 6+ messages in thread
From: Alviro Iskandar Setiawan @ 2025-07-16 0:03 UTC (permalink / raw)
To: Jens Axboe
Cc: Ammar Faizi, GNU/Weeb Mailing List, Linux Kernel Mailing List,
io-uring Mailing List
On Tue, Jul 15, 2025 at 9:10 PM Jens Axboe wrote:
> Maybe just bring back the configure parts? The test, as mentioned in
> that commit, is pretty useless.
Ok, I'll send a v2 with the test omitted.
-- Viro
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-07-16 0:03 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-15 5:06 [PATCH liburing 0/3] Bring back `CONFIG_HAVE_MEMFD_CREATE` to fix Android build error Alviro Iskandar Setiawan
2025-07-15 5:06 ` [PATCH liburing 1/3] Revert "test/io_uring_register: kill old memfd test" Alviro Iskandar Setiawan
2025-07-15 14:10 ` Jens Axboe
2025-07-16 0:03 ` Alviro Iskandar Setiawan
2025-07-15 5:06 ` [PATCH liburing 2/3] test: Move `memfd_create()` to helpers.c, make it accessible for all tests Alviro Iskandar Setiawan
2025-07-15 5:06 ` [PATCH liburing 3/3] examples: Add `memfd_create()` helper Alviro Iskandar Setiawan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).