aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2023-11-03 22:22:37 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-11-03 22:22:37 +0000
commit4c29624a4233693a8eb9e59470b73f714e280310 (patch)
tree23567cf402b0b042193cbd1d43fdc59f638ba029
parenteb60e8ce7f89c11e0d880fb9d04a4db3b3121250 (diff)
parent5327f18a1b91d5b90f4996f2963b971caac99db7 (diff)
downloadlinux-kselftest-4c29624a4233693a8eb9e59470b73f714e280310.tar.gz
ANDROID: Get kernel version to handle UFFD_POISON. am: adab44284b am: 0512905cbd am: 5327f18a1b
Original change: https://android-review.googlesource.com/c/platform/external/linux-kselftest/+/2815113 Change-Id: I3dc7419ddbed29843413e98153854be13a8e1200 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--tools/testing/selftests/vm/userfaultfd.c33
1 files changed, 25 insertions, 8 deletions
diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c
index a3c0bf6af646..c22127e72a3c 100644
--- a/tools/testing/selftests/vm/userfaultfd.c
+++ b/tools/testing/selftests/vm/userfaultfd.c
@@ -59,6 +59,8 @@
#include <inttypes.h>
#include <stdint.h>
#include <sys/random.h>
+#include <linux/version.h>
+#include <sys/utsname.h>
#include "../kselftest.h"
#include "vm_util.h"
@@ -407,6 +409,20 @@ static inline uint64_t uffd_minor_feature(void)
return 0;
}
+/* b/308714445
+ * _UFFDIO_POISON unsupported in kernel <6.6
+ */
+static uint32_t get_kernel_version(void)
+{
+ uint32_t major, minor, patch;
+ struct utsname info;
+
+ uname(&info);
+ if (sscanf(info.release, "%u.%u.%u", &major, &minor, &patch) != 3)
+ return 0;
+ return KERNEL_VERSION(major, minor, patch);
+}
+
static uint64_t get_expected_ioctls(uint64_t mode)
{
uint64_t ioctls = UFFD_API_RANGE_IOCTLS;
@@ -420,6 +436,15 @@ static uint64_t get_expected_ioctls(uint64_t mode)
if (!((mode & UFFDIO_REGISTER_MODE_MINOR) && test_uffdio_minor))
ioctls &= ~(1 << _UFFDIO_CONTINUE);
+ static uint32_t kernel_version = 0;
+ if (kernel_version == 0) {
+ kernel_version = get_kernel_version();
+ }
+ if (kernel_version < KERNEL_VERSION(6, 6, 0)) {
+ // UFFDIO_POISON not supported until kernel 6.6.
+ ioctls &= ~(1 << _UFFDIO_POISON);
+ }
+
return ioctls;
}
@@ -429,14 +454,6 @@ static void assert_expected_ioctls_present(uint64_t mode, uint64_t ioctls)
uint64_t actual = ioctls & expected;
if (actual != expected) {
- /* b/308714445
- * _UFFDIO_POISON unsupported in kernel <6.6
- */
-#ifdef __ANDROID__
- if ((expected & ~(1 << _UFFDIO_POISON)) == actual) {
- return;
- }
-#endif
err("missing ioctl(s): expected %"PRIx64" actual: %"PRIx64,
expected, actual);
}