Merge "Fix ARM related issues in userfaultfd selftest"
diff --git a/Android.bp b/Android.bp
index 43ec24a..0b9166c 100644
--- a/Android.bp
+++ b/Android.bp
@@ -96,6 +96,14 @@
     test_per_src: true,
 }
 
+// binderfs test
+cc_test {
+    name: "kselftest_binderfs_tests",
+    relative_install_path: "linux-kselftest/filesystems/binderfs",
+    srcs: ["tools/testing/selftests/filesystems/binderfs/binderfs_test.c"],
+    defaults: ["kselftest_defaults"],
+}
+
 // breakpoints test
 cc_test {
     name: "kselftest_breakpoints_tests",
diff --git a/OWNERS b/OWNERS
index 64bf926..3ae489a 100644
--- a/OWNERS
+++ b/OWNERS
@@ -1,2 +1,3 @@
 drosen@google.com
+smuckle@google.com
 willmcvicker@google.com
diff --git a/android/kselftest_test_list.mk b/android/kselftest_test_list.mk
index dc65a47..07df6fc 100644
--- a/android/kselftest_test_list.mk
+++ b/android/kselftest_test_list.mk
@@ -12,6 +12,7 @@
 
 # From Android.bp
 kselftest_modules += \
+  kselftest_binderfs_tests_binderfs_test \
   kselftest_breakpoints_tests_breakpoint_test \
   kselftest_breakpoints_tests_breakpoint_test_arm64 \
   kselftest_breakpoints_tests_step_after_suspend_test \
diff --git a/android/patches/0020-selftests-binderfs-fix-Wunused-label-error.patch b/android/patches/0020-selftests-binderfs-fix-Wunused-label-error.patch
new file mode 100644
index 0000000..8b872f1
--- /dev/null
+++ b/android/patches/0020-selftests-binderfs-fix-Wunused-label-error.patch
@@ -0,0 +1,31 @@
+From c4970a0b5461b65ce3b7d1c40a76672bd18d3ba5 Mon Sep 17 00:00:00 2001
+From: Carlos Llamas <cmllamas@google.com>
+Date: Mon, 26 Jul 2021 17:06:02 +0000
+Subject: [PATCH 1/2] selftests/binderfs: fix Wunused-label error
+
+Fix the following build issue:
+  tools/testing/selftests/filesystems/binderfs/binderfs_test.c:244:1:
+  error: unused label 'on_error' [-Werror,-Wunused-label]
+  on_error:
+  ^~~~~~~~~
+
+Signed-off-by: Carlos Llamas <cmllamas@google.com>
+---
+ tools/testing/selftests/filesystems/binderfs/binderfs_test.c | 1 -
+ 1 file changed, 1 deletion(-)
+
+diff --git a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
+index 8c2ed962e1c7..540ad4840495 100644
+--- a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
++++ b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
+@@ -241,7 +241,6 @@ static void __do_binderfs_test(void)
+ 	/* binder-control device removal failed as expected */
+ 	ksft_inc_xfail_cnt();
+ 
+-on_error:
+ 	ret = umount2("/dev/binderfs", MNT_DETACH);
+ 	keep ?: rmdir_protect_errno("/dev/binderfs");
+ 	if (ret < 0)
+-- 
+2.32.0.432.gabb21c7263-goog
+
diff --git a/android/patches/0021-selftests-binderfs-skip-unprivileged-test-when-USER_.patch b/android/patches/0021-selftests-binderfs-skip-unprivileged-test-when-USER_.patch
new file mode 100644
index 0000000..8a5af57
--- /dev/null
+++ b/android/patches/0021-selftests-binderfs-skip-unprivileged-test-when-USER_.patch
@@ -0,0 +1,36 @@
+From e51806a0b6918cefbd068cbb8100f410e7b01970 Mon Sep 17 00:00:00 2001
+From: Carlos Llamas <cmllamas@google.com>
+Date: Mon, 26 Jul 2021 17:12:42 +0000
+Subject: [PATCH 2/2] selftests/binderfs: skip unprivileged test when !USER_NS
+
+Binderfs unprivileged test requires CONFIG_USER_NS to be set. However,
+this option is not required by Android platforms. Lets skip the test
+as the underlying routine __do_binderfs_test() has already been checked
+by the binderfs_test_privileged() anyway.
+
+Signed-off-by: Carlos Llamas <cmllamas@google.com>
+---
+ .../testing/selftests/filesystems/binderfs/binderfs_test.c | 7 +++++++
+ 1 file changed, 7 insertions(+)
+
+diff --git a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
+index 540ad4840495..397bf265ba97 100644
+--- a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
++++ b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
+@@ -262,6 +262,13 @@ static void binderfs_test_privileged()
+ 
+ static void binderfs_test_unprivileged()
+ {
++	/* This test depends on USER_NS which is not required by Android */
++	if (access("/proc/self/ns/user", F_OK) != 0) {
++		ksft_test_result_skip("%s: user namespace not supported\n",
++				__func__);
++		return;
++	}
++
+ 	change_to_userns();
+ 	__do_binderfs_test();
+ }
+-- 
+2.32.0.432.gabb21c7263-goog
+
diff --git a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
index 8c2ed96..397bf26 100644
--- a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
+++ b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
@@ -241,7 +241,6 @@
 	/* binder-control device removal failed as expected */
 	ksft_inc_xfail_cnt();
 
-on_error:
 	ret = umount2("/dev/binderfs", MNT_DETACH);
 	keep ?: rmdir_protect_errno("/dev/binderfs");
 	if (ret < 0)
@@ -263,6 +262,13 @@
 
 static void binderfs_test_unprivileged()
 {
+	/* This test depends on USER_NS which is not required by Android */
+	if (access("/proc/self/ns/user", F_OK) != 0) {
+		ksft_test_result_skip("%s: user namespace not supported\n",
+				__func__);
+		return;
+	}
+
 	change_to_userns();
 	__do_binderfs_test();
 }