aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-11-04 03:08:25 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-11-04 03:08:25 +0000
commit19a3246c3418d0debfbbc9f5f7fc2ec139a74358 (patch)
tree23567cf402b0b042193cbd1d43fdc59f638ba029
parenta6fd9baab3fb2cbdc8b821ebfcdbcf9bcd610a11 (diff)
parent829fff08776ac54016da5bbfb30a7e96572dc97e (diff)
downloadlinux-kselftest-19a3246c3418d0debfbbc9f5f7fc2ec139a74358.tar.gz
Snap for 11051137 from 829fff08776ac54016da5bbfb30a7e96572dc97e to 24Q1-release
Change-Id: I534afd4db05191c507788b591619db40f2047fd3
-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);
}