userfaultfd: Add test using UFFDIO_POISON
PATCH v2 1/1 userfaultfd: Add test using UFFDIO_POISON
--- configure.ac | 1 + include/lapi/userfaultfd.h | 13 ++ .../kernel/syscalls/userfaultfd/.gitignore | 1 + .../kernel/syscalls/userfaultfd/Makefile | 1 + .../syscalls/userfaultfd/userfaultfd06.c | 141 ++++++++++++++++++ 5 files changed, 157 insertions(+) create mode 100644 testcases/kernel/syscalls/userfaultfd/userfaultfd06.c
configure.ac +1 -0
@@ -278,6 +278,7 @@ AC_CHECK_TYPES([struct sockaddr_vm],,,[ ]) AC_CHECK_TYPES([struct uffdio_move],,,[#include <linux/userfaultfd.h>]) +AC_CHECK_TYPES([struct uffdio_poison],,,[#include <linux/userfaultfd.h>]) AC_CHECK_TYPES([struct uffdio_writeprotect],,,[#include <linux/userfaultfd.h>]) # Tools knobs
include/lapi/userfaultfd.h +13 -0
@@ -233,6 +233,19 @@ struct uffdio_writeprotect { };#endif /* HAVE_STRUCT_UFFDIO_WRITEPROTECT */ +#ifndef HAVE_STRUCT_UFFDIO_POISON +#define UFFD_FEATURE_POISON (1<<14) +#define _UFFDIO_POISON (0x08) +#define UFFDIO_POISON _IOWR(UFFDIO, _UFFDIO_POISON, \ + struct uffdio_poison) +struct uffdio_poison { +struct uffdio_range range; +#define UFFDIO_POISON_MODE_DONTWAKE ((__u64)1<<0) +__u64 mode; +__s64 updated; +}; +#endif /* HAVE_STRUCT_UFFDIO_POISON */ +#define SAFE_USERFAULTFD (flags, retry) \ safe_userfaultfd(__FILE__, __LINE__, (flags), (retry))
testcases/kernel/syscalls/userfaultfd/.gitignore +1 -0
@@ -3,3 +3,4 @@ /userfaultfd03 /userfaultfd04 /userfaultfd05 +/userfaultfd06
testcases/kernel/syscalls/userfaultfd/Makefile +1 -0
@@ -16,3 +16,4 @@ userfaultfd02: CFLAGS += -pthread userfaultfd03: CFLAGS += -pthread userfaultfd04: CFLAGS += -pthread userfaultfd05: CFLAGS += -pthread +userfaultfd06: CFLAGS += -pthread
testcases/kernel/syscalls/userfaultfd/userfaultfd06.c new file +141 -0
141 lines not on this page · raw message
Signature · 5 lines
2.53.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
testcases/kernel/syscalls/userfaultfd/userfaultfd06.c line 60
Quoted 8 lines
testcases/kernel/syscalls/userfaultfd/userfaultfd06.c new file +8
-0+static void *handle_thread (void ) +{ +static struct uffd_msg msg; +struct uffdio_poison uffdio_poison = {}; +struct pollfd pollfd; +int nready; + +SAFE_PTHREAD_BARRIER_WAIT (&barrier);
I still do not understand why we need the barrier here. The thread that tries to access the memory should block until this thread processes the event sicne the usefaultfd range was registered before the memory is accessed.
Also the same pattern is present in rest of the usefaultfd tests, so either we need this barrier in all of them, or it shouldn't be needed here.
And the test seems to work just fine if I remove the barrier code.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 10 lines · Cyril Hrubis
I still do not understand why we need the barrier here. The thread that tries to access the memory should block until this thread processes the event sicne the usefaultfd range was registered before the memory is accessed.
Also the same pattern is present in rest of the usefaultfd tests, so either we need this barrier in all of them, or it shouldn't be needed here.
And the test seems to work just fine if I remove the barrier code.
I submitted a v3 without the barrier code. Seems safe.
Best,
R
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp