aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2023-11-01 19:22:42 -0700
committerChristopher Ferris <cferris@google.com>2023-11-03 13:20:10 -0700
commitadab44284b49c47f55067619a7c0d1cd5890d7e1 (patch)
tree23567cf402b0b042193cbd1d43fdc59f638ba029
parent6f52d50ac97322b7e75a9dfc1fcae9f48ecab581 (diff)
downloadlinux-kselftest-adab44284b49c47f55067619a7c0d1cd5890d7e1.tar.gz
ANDROID: Get kernel version to handle UFFD_POISON.
The 6.6 kernels are the first version to handle the UFFD_POISON ioctl, so skip checking for this ioctl based on the kernel being tested. Bug: 308714445 Test: Ran atest -a vts_linux_kselftest_x86_32 Test: Ran atest -a vts_linux_kselftest_x86_64 Change-Id: Ib4cbac94776efb2d09f19333075da839dc274635
-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);
}