Skip to contentSkip to conversation

selftests: capabilities: remove duplicate unneeded defines

PATCH In review Muhammad Usama Anjum 2 participants 6 messages Oct 6, 2023 – Oct 24, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/4 selftests: capabilities: remove duplicate unneeded defines

These duplicate defines should automatically be picked up from kernel headers. Use KHDR_INCLUDES to add kernel header files.

---
 tools/testing/selftests/capabilities/Makefile       | 2 +-
 tools/testing/selftests/capabilities/test_execve.c  | 8 --------
 tools/testing/selftests/capabilities/validate_cap.c | 8 --------
 3 files changed, 1 insertion(+), 17 deletions(-)
tools/testing/selftests/capabilities/Makefile +1 -1
index 6e9d98d457d5b..411ac098308f1 100644
@@ -2,7 +2,7 @@
 TEST_GEN_FILES := validate_cap
 TEST_GEN_PROGS := test_execve
 
-CFLAGS += -O2 -g -std=gnu99 -Wall
+CFLAGS += -O2 -g -std=gnu99 -Wall $(KHDR_INCLUDES)
 LDLIBS += -lcap-ng -lrt -ldl
 
 include ../lib.mk
tools/testing/selftests/capabilities/test_execve.c +0 -8
index df0ef02b40367..e3a352b020a79 100644
@@ -20,14 +20,6 @@
 
 #include "../kselftest.h"
 
-#ifndef PR_CAP_AMBIENT
-#define PR_CAP_AMBIENT			47
-# define PR_CAP_AMBIENT_IS_SET		1
-# define PR_CAP_AMBIENT_RAISE		2
-# define PR_CAP_AMBIENT_LOWER		3
-# define PR_CAP_AMBIENT_CLEAR_ALL	4
-#endif
-
 static int nerrs;
 static pid_t mpid;	/*  main() pid is used to avoid duplicate test counts */
 
tools/testing/selftests/capabilities/validate_cap.c +0 -8
index cdfc94268fe6e..60b4e7b716a75 100644
@@ -9,14 +9,6 @@
 
 #include "../kselftest.h"
 
-#ifndef PR_CAP_AMBIENT
-#define PR_CAP_AMBIENT			47
-# define PR_CAP_AMBIENT_IS_SET		1
-# define PR_CAP_AMBIENT_RAISE		2
-# define PR_CAP_AMBIENT_LOWER		3
-# define PR_CAP_AMBIENT_CLEAR_ALL	4
-#endif
-
 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 19)
 # define HAVE_GETAUXVAL
 #endif
Signature · 1 line
2.40.1
#1 lore raw

PATCH v2 2/4 selftests: clone3: remove duplicate defines

Remove duplicate defines which are already included in kernel headers. MAX_PID_NS_LEVEL macro is used inside kernel only. It isn't exposed to userspace. So it is never defined in test application. Remove #ifndef in this case.

---
Changes since v1:
- Make patch explanation better

---
 .../clone3/clone3_cap_checkpoint_restore.c          |  2 --
 .../testing/selftests/clone3/clone3_clear_sighand.c |  4 ----
 tools/testing/selftests/clone3/clone3_selftests.h   | 13 -------------
 tools/testing/selftests/clone3/clone3_set_tid.c     |  2 --
 4 files changed, 21 deletions(-)
tools/testing/selftests/clone3/clone3_cap_checkpoint_restore.c +0 -2
index 52d3f0364bdaa..31b56d6256550 100644
@@ -27,9 +27,7 @@
 #include "../kselftest_harness.h"
 #include "clone3_selftests.h"
 
-#ifndef MAX_PID_NS_LEVEL
 #define MAX_PID_NS_LEVEL 32
-#endif
 
 static void child_exit(int ret)
 {
tools/testing/selftests/clone3/clone3_clear_sighand.c +0 -4
index 47a8c0fc3676b..54a8b2445be99 100644
@@ -16,10 +16,6 @@
 #include "../kselftest.h"
 #include "clone3_selftests.h"
 
-#ifndef CLONE_CLEAR_SIGHAND
-#define CLONE_CLEAR_SIGHAND 0x100000000ULL
-#endif
-
 static void nop_handler(int signo)
 {
 }
tools/testing/selftests/clone3/clone3_selftests.h +0 -13
index e81ffaaee02ba..3d2663fe50ba5 100644
@@ -15,10 +15,6 @@
 
 #define ptr_to_u64(ptr) ((__u64)((uintptr_t)(ptr)))
 
-#ifndef CLONE_INTO_CGROUP
-#define CLONE_INTO_CGROUP 0x200000000ULL /* Clone into a specific cgroup given the right permissions. */
-#endif
-
 #ifndef __NR_clone3
 #define __NR_clone3 -1
 #endif
@@ -32,18 +28,9 @@ struct __clone_args {
 	__aligned_u64 stack;
 	__aligned_u64 stack_size;
 	__aligned_u64 tls;
-#ifndef CLONE_ARGS_SIZE_VER0
-#define CLONE_ARGS_SIZE_VER0 64	/* sizeof first published struct */
-#endif
 	__aligned_u64 set_tid;
 	__aligned_u64 set_tid_size;
-#ifndef CLONE_ARGS_SIZE_VER1
-#define CLONE_ARGS_SIZE_VER1 80	/* sizeof second published struct */
-#endif
 	__aligned_u64 cgroup;
-#ifndef CLONE_ARGS_SIZE_VER2
-#define CLONE_ARGS_SIZE_VER2 88	/* sizeof third published struct */
-#endif
 };
 
 static pid_t sys_clone3(struct __clone_args *args, size_t size)
tools/testing/selftests/clone3/clone3_set_tid.c +0 -2
index 0229e9ebb995e..ed785afb60770 100644
@@ -23,9 +23,7 @@
 #include "../kselftest.h"
 #include "clone3_selftests.h"
 
-#ifndef MAX_PID_NS_LEVEL
 #define MAX_PID_NS_LEVEL 32
-#endif
 
 static int pipe_1[2];
 static int pipe_2[2];
Signature · 1 line
2.40.1
#2 lore raw

PATCH v2 3/4 selftests: core: remove duplicate defines

In reply to Muhammad Usama Anjum

Remove duplicate defines which are already defined in kernel headers and re-definition isn't required.

---
 .../testing/selftests/core/close_range_test.c | 28 -------------------
 1 file changed, 28 deletions(-)
tools/testing/selftests/core/close_range_test.c +0 -28
index 749239930ca83..534576f06df1c 100644
@@ -16,34 +16,6 @@
 #include "../kselftest_harness.h"
 #include "../clone3/clone3_selftests.h"
 
-#ifndef __NR_close_range
-	#if defined __alpha__
-		#define __NR_close_range 546
-	#elif defined _MIPS_SIM
-		#if _MIPS_SIM == _MIPS_SIM_ABI32	/* o32 */
-			#define __NR_close_range (436 + 4000)
-		#endif
-		#if _MIPS_SIM == _MIPS_SIM_NABI32	/* n32 */
-			#define __NR_close_range (436 + 6000)
-		#endif
-		#if _MIPS_SIM == _MIPS_SIM_ABI64	/* n64 */
-			#define __NR_close_range (436 + 5000)
-		#endif
-	#elif defined __ia64__
-		#define __NR_close_range (436 + 1024)
-	#else
-		#define __NR_close_range 436
-	#endif
-#endif
-
-#ifndef CLOSE_RANGE_UNSHARE
-#define CLOSE_RANGE_UNSHARE	(1U << 1)
-#endif
-
-#ifndef CLOSE_RANGE_CLOEXEC
-#define CLOSE_RANGE_CLOEXEC	(1U << 2)
-#endif
-
 static inline int sys_close_range(unsigned int fd, unsigned int max_fd,
 				  unsigned int flags)
 {
Signature · 1 line
2.40.1
#3 lore raw

Re: [PATCH v2 3/4] selftests: core: remove duplicate defines

Quoted 5 lines · Muhammad Usama Anjum

Remove duplicate defines which are already defined in kernel headers and re-definition isn't required.

---

Hi Muhammad,

Currently when building kselftest against next-master with arm64 arch and defconfig+kselftest “error: 'CLOSE_RANGE_UNSHARE' undeclared (first use in this function)” is observed.

The bisect log is below and a full log from a failing test job can be seen here:

https://storage.kernelci.org/next/master/next-20231023/arm64/defconfig+kselftest/gcc-10/logs/kselftest.log

close_range_test.c: In function 'close_range_unshare':
close_range_test.c:111:11: error: 'CLOSE_RANGE_UNSHARE' undeclared (first use in this function)

  111 |           CLOSE_RANGE_UNSHARE);
      |           ^~~~~~~~~~~~~~~~~~~

close_range_test.c:111:11: note: each undeclared identifier is reported only once for each function it appears in close_range_test.c: In function 'close_range_unshare_capped':
close_range_test.c:200:11: error: 'CLOSE_RANGE_UNSHARE' undeclared (first use in this function)

  200 |           CLOSE_RANGE_UNSHARE);
      |           ^~~~~~~~~~~~~~~~~~~
close_range_test.c: In function 'close_range_cloexec':
close_range_test.c:234:36: error: 'CLOSE_RANGE_CLOEXEC' undeclared
(first use in this function)
  234 |  ret = sys_close_range(1000, 1000, CLOSE_RANGE_CLOEXEC);
      |                                    ^~~~~~~~~~~~~~~~~~~
close_range_test.c: In function 'close_range_cloexec_unshare':
close_range_test.c:302:36: error: 'CLOSE_RANGE_CLOEXEC' undeclared
(first use in this function)
  302 |  ret = sys_close_range(1000, 1000, CLOSE_RANGE_CLOEXEC);
      |                                    ^~~~~~~~~~~~~~~~~~~
close_range_test.c:317:32: error: 'CLOSE_RANGE_UNSHARE' undeclared
(first use in this function)
  317 |          CLOSE_RANGE_CLOEXEC | CLOSE_RANGE_UNSHARE);
      |                                ^~~~~~~~~~~~~~~~~~~
close_range_test.c: In function 'close_range_cloexec_syzbot':
close_range_test.c:378:33: error: 'CLOSE_RANGE_CLOEXEC' undeclared
(first use in this function)
  378 |   ret = sys_close_range(3, ~0U, CLOSE_RANGE_CLOEXEC);
      |                                 ^~~~~~~~~~~~~~~~~~~

close_range_test.c: In function 'close_range_cloexec_unshare_syzbot':
close_range_test.c:472:34: error: 'CLOSE_RANGE_UNSHARE' undeclared (first use in this function)
472 | ret = sys_close_range(3, ~0U, CLOSE_RANGE_UNSHARE |

      |                                  ^~~~~~~~~~~~~~~~~~~
close_range_test.c:473:13: error: 'CLOSE_RANGE_CLOEXEC' undeclared
(first use in this function)
  473 |             CLOSE_RANGE_CLOEXEC);
      |             ^~~~~~~~~~~~~~~~~~~

make[4]: *** [../lib.mk:181:
/tmp/kci/linux/build/kselftest/core/close_range_test] Error 1

git bisect log
git bisect start
# good: [58720809f52779dc0f08e53e54b014209d13eebb] Linux 6.6-rc6 git bisect good 58720809f52779dc0f08e53e54b014209d13eebb
# bad: [2030579113a1b1b5bfd7ff24c0852847836d8fd1] Add linux-next specific files for 20231020
git bisect bad 2030579113a1b1b5bfd7ff24c0852847836d8fd1
# good: [aa531ca5bb35637b6d235df5feba57ed94d3a462] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma.git
git bisect good aa531ca5bb35637b6d235df5feba57ed94d3a462
# good: [37a9b505514f0ed4447757452f1e39d3a373df59] Merge branch 'for-next' of
https://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394.git
git bisect good 37a9b505514f0ed4447757452f1e39d3a373df59
# good: [695ee55348f6c3c7ec5f953ab297b4db9501962b] Merge branch 'for-next' of
git://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git
git bisect good 695ee55348f6c3c7ec5f953ab297b4db9501962b
# skip: [150dc54505f3395010784d2a5c8b2e0e9b2b2f37] Merge branch 'counter-next' of
git://git.kernel.org/pub/scm/linux/kernel/git/wbg/counter.git
git bisect skip 150dc54505f3395010784d2a5c8b2e0e9b2b2f37
# good: [bae023765199bef243b49c0f8860a3290a5c9f6d] staging: iio:
resolver: ad2s1210: implement hysteresis as channel attr
git bisect good bae023765199bef243b49c0f8860a3290a5c9f6d
# good: [337c88ee5fb65f9c34ca7bb129915cb59de687b3] Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/vkoul/dmaengine.git
git bisect good 337c88ee5fb65f9c34ca7bb129915cb59de687b3
# good: [248f0927e11e09e6285383938b5c4b87079ee5a7] Merge branch 'for-next' of
git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl.git
git bisect good 248f0927e11e09e6285383938b5c4b87079ee5a7
# bad: [3e2f5dfe32e1a8fbd034b1060bd30b9b1179b4c7] Merge branch 'rtc-next' of
git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git
git bisect bad 3e2f5dfe32e1a8fbd034b1060bd30b9b1179b4c7
# bad: [1f6421f11948d0de9216b8f1c439c21dbc90da91] Merge branch 'next' of
git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git
git bisect bad 1f6421f11948d0de9216b8f1c439c21dbc90da91
# bad: [34dce23f7e405ffb4eca04e83ee10c03a4cffb9b] selftests/clone3:
Report descriptive test names
git bisect bad 34dce23f7e405ffb4eca04e83ee10c03a4cffb9b
# bad: [d3772e7badd2cd3813e2efba0034f6e39aecc97f] selftests/mm:
Substitute attribute with a macro
git bisect bad d3772e7badd2cd3813e2efba0034f6e39aecc97f
# good: [071af0c9e582bc47e379e39490a2bc1adfe4ec68] selftests: timers:
Convert posix_timers test to generate KTAP output
git bisect good 071af0c9e582bc47e379e39490a2bc1adfe4ec68
# bad: [2531f374f922e77ba51f24d1aa6fa11c7f4c36b8] Documentation:
kselftests: Remove references to bpf tests
git bisect bad 2531f374f922e77ba51f24d1aa6fa11c7f4c36b8
# good: [44eebacd6b8f633eb3a38a6db093658636b844e8] selftests: clone3:
remove duplicate defines
git bisect good 44eebacd6b8f633eb3a38a6db093658636b844e8
# bad: [ec54424923cf943b51dd5bf75fcbe27b0ca2c6ef] selftests: core:
remove duplicate defines
git bisect bad ec54424923cf943b51dd5bf75fcbe27b0ca2c6ef

# first bad commit: [ec54424923cf943b51dd5bf75fcbe27b0ca2c6ef]
selftests: core: remove duplicate defines

Thanks,
Aishwarya

#4 lore raw

Re: [PATCH v2 3/4] selftests: core: remove duplicate defines

Hi Aishwarya,

Quoted 6 lines · Aishwarya TCV
Quoted 3 lines · Muhammad Usama Anjum

Remove duplicate defines which are already defined in kernel headers and re-definition isn't required.

Quoted 8 lines
Quoted 2 lines

---

Hi Muhammad,

Currently when building kselftest against next-master with arm64 arch and defconfig+kselftest “error: 'CLOSE_RANGE_UNSHARE' undeclared (first use in this function)” is observed.

Thanks for reporting. I've sent the fix:
https://lore.kernel.org/all/[email protected]

Quoted 112 lines

The bisect log is below and a full log from a failing test job can be seen here:

https://storage.kernelci.org/next/master/next-20231023/arm64/defconfig+kselftest/gcc-10/logs/kselftest.log

close_range_test.c: In function 'close_range_unshare':
close_range_test.c:111:11: error: 'CLOSE_RANGE_UNSHARE' undeclared (first use in this function)

  111 |           CLOSE_RANGE_UNSHARE);
      |           ^~~~~~~~~~~~~~~~~~~

close_range_test.c:111:11: note: each undeclared identifier is reported only once for each function it appears in close_range_test.c: In function 'close_range_unshare_capped':
close_range_test.c:200:11: error: 'CLOSE_RANGE_UNSHARE' undeclared (first use in this function)

  200 |           CLOSE_RANGE_UNSHARE);
      |           ^~~~~~~~~~~~~~~~~~~
close_range_test.c: In function 'close_range_cloexec':
close_range_test.c:234:36: error: 'CLOSE_RANGE_CLOEXEC' undeclared
(first use in this function)
  234 |  ret = sys_close_range(1000, 1000, CLOSE_RANGE_CLOEXEC);
      |                                    ^~~~~~~~~~~~~~~~~~~
close_range_test.c: In function 'close_range_cloexec_unshare':
close_range_test.c:302:36: error: 'CLOSE_RANGE_CLOEXEC' undeclared
(first use in this function)
  302 |  ret = sys_close_range(1000, 1000, CLOSE_RANGE_CLOEXEC);
      |                                    ^~~~~~~~~~~~~~~~~~~
close_range_test.c:317:32: error: 'CLOSE_RANGE_UNSHARE' undeclared
(first use in this function)
  317 |          CLOSE_RANGE_CLOEXEC | CLOSE_RANGE_UNSHARE);
      |                                ^~~~~~~~~~~~~~~~~~~
close_range_test.c: In function 'close_range_cloexec_syzbot':
close_range_test.c:378:33: error: 'CLOSE_RANGE_CLOEXEC' undeclared
(first use in this function)
  378 |   ret = sys_close_range(3, ~0U, CLOSE_RANGE_CLOEXEC);
      |                                 ^~~~~~~~~~~~~~~~~~~

close_range_test.c: In function 'close_range_cloexec_unshare_syzbot':
close_range_test.c:472:34: error: 'CLOSE_RANGE_UNSHARE' undeclared (first use in this function)
472 | ret = sys_close_range(3, ~0U, CLOSE_RANGE_UNSHARE |

      |                                  ^~~~~~~~~~~~~~~~~~~
close_range_test.c:473:13: error: 'CLOSE_RANGE_CLOEXEC' undeclared
(first use in this function)
  473 |             CLOSE_RANGE_CLOEXEC);
      |             ^~~~~~~~~~~~~~~~~~~

make[4]: *** [../lib.mk:181:
/tmp/kci/linux/build/kselftest/core/close_range_test] Error 1

git bisect log
git bisect start
# good: [58720809f52779dc0f08e53e54b014209d13eebb] Linux 6.6-rc6 git bisect good 58720809f52779dc0f08e53e54b014209d13eebb
# bad: [2030579113a1b1b5bfd7ff24c0852847836d8fd1] Add linux-next specific files for 20231020
git bisect bad 2030579113a1b1b5bfd7ff24c0852847836d8fd1
# good: [aa531ca5bb35637b6d235df5feba57ed94d3a462] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma.git
git bisect good aa531ca5bb35637b6d235df5feba57ed94d3a462
# good: [37a9b505514f0ed4447757452f1e39d3a373df59] Merge branch 'for-next' of
https://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394.git
git bisect good 37a9b505514f0ed4447757452f1e39d3a373df59
# good: [695ee55348f6c3c7ec5f953ab297b4db9501962b] Merge branch 'for-next' of
git://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git
git bisect good 695ee55348f6c3c7ec5f953ab297b4db9501962b
# skip: [150dc54505f3395010784d2a5c8b2e0e9b2b2f37] Merge branch 'counter-next' of
git://git.kernel.org/pub/scm/linux/kernel/git/wbg/counter.git
git bisect skip 150dc54505f3395010784d2a5c8b2e0e9b2b2f37
# good: [bae023765199bef243b49c0f8860a3290a5c9f6d] staging: iio:
resolver: ad2s1210: implement hysteresis as channel attr
git bisect good bae023765199bef243b49c0f8860a3290a5c9f6d
# good: [337c88ee5fb65f9c34ca7bb129915cb59de687b3] Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/vkoul/dmaengine.git
git bisect good 337c88ee5fb65f9c34ca7bb129915cb59de687b3
# good: [248f0927e11e09e6285383938b5c4b87079ee5a7] Merge branch 'for-next' of
git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl.git
git bisect good 248f0927e11e09e6285383938b5c4b87079ee5a7
# bad: [3e2f5dfe32e1a8fbd034b1060bd30b9b1179b4c7] Merge branch 'rtc-next' of
git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git
git bisect bad 3e2f5dfe32e1a8fbd034b1060bd30b9b1179b4c7
# bad: [1f6421f11948d0de9216b8f1c439c21dbc90da91] Merge branch 'next' of
git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git
git bisect bad 1f6421f11948d0de9216b8f1c439c21dbc90da91
# bad: [34dce23f7e405ffb4eca04e83ee10c03a4cffb9b] selftests/clone3:
Report descriptive test names
git bisect bad 34dce23f7e405ffb4eca04e83ee10c03a4cffb9b
# bad: [d3772e7badd2cd3813e2efba0034f6e39aecc97f] selftests/mm:
Substitute attribute with a macro
git bisect bad d3772e7badd2cd3813e2efba0034f6e39aecc97f
# good: [071af0c9e582bc47e379e39490a2bc1adfe4ec68] selftests: timers:
Convert posix_timers test to generate KTAP output
git bisect good 071af0c9e582bc47e379e39490a2bc1adfe4ec68
# bad: [2531f374f922e77ba51f24d1aa6fa11c7f4c36b8] Documentation:
kselftests: Remove references to bpf tests
git bisect bad 2531f374f922e77ba51f24d1aa6fa11c7f4c36b8
# good: [44eebacd6b8f633eb3a38a6db093658636b844e8] selftests: clone3:
remove duplicate defines
git bisect good 44eebacd6b8f633eb3a38a6db093658636b844e8
# bad: [ec54424923cf943b51dd5bf75fcbe27b0ca2c6ef] selftests: core:
remove duplicate defines
git bisect bad ec54424923cf943b51dd5bf75fcbe27b0ca2c6ef

# first bad commit: [ec54424923cf943b51dd5bf75fcbe27b0ca2c6ef]
selftests: core: remove duplicate defines

Thanks,
Aishwarya

Signature · 2 lines
BR,
Muhammad Usama Anjum
#5 lore raw

PATCH v2 4/4 selftests: firmware: remove duplicate unneeded defines

In reply to Muhammad Usama Anjum

These duplicate defines should automatically be picked up from kernel headers.

---
Changes since v1:
- Make the patch explanation better

---
 tools/testing/selftests/firmware/fw_namespace.c | 4 ----
 1 file changed, 4 deletions(-)
tools/testing/selftests/firmware/fw_namespace.c +0 -4
index 4c6f0cd83c5b0..04757dc7e5467 100644
@@ -17,10 +17,6 @@
 #include <sys/wait.h>
 #include <unistd.h>
 
-#ifndef CLONE_NEWNS
-# define CLONE_NEWNS 0x00020000
-#endif
-
 static char *fw_path = NULL;
 
 static void die(char *fmt, ...)
Signature · 1 line
2.40.1