Skip to contentSkip to conversation

selftests/vDSO: Fix undefined CLONE_NEWTIME by including

PATCH In review Purva Yeshi 2 participants 6 messages Jan 26, 2025 – Feb 1, 2025

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

PATCH 1/1 selftests/vDSO: Fix undefined CLONE_NEWTIME by including

Fix the build failure caused by the undefined CLONE_NEWTIME. Include the linux/sched.h header file where the function is defined to ensure successful compilation of the selftests.

---
 tools/testing/selftests/vDSO/vdso_test_getrandom.c | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/vDSO/vdso_test_getrandom.c +2 -0
index 95057f7567db..b2c9cf15878b 100644
@@ -29,6 +29,8 @@
 #include "vdso_config.h"
 #include "vdso_call.h"
 
+#include <linux/sched.h>
+
 #ifndef timespecsub
 #define	timespecsub(tsp, usp, vsp)					\
 	do {								\
Signature · 1 line
2.34.1
#1 lore raw

Le 26/01/2025 à 11:59, Purva Yeshi a écrit :

Quoted 5 lines

[Vous ne recevez pas souvent de courriers de [email protected]. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ]

Fix the build failure caused by the undefined CLONE_NEWTIME. Include the linux/sched.h header file where the function is defined to ensure successful compilation of the selftests.

This is supposed to be already fixed by commit 34d5b600172b ("selftests: vDSO: Explicitly include sched.h")

Can you explain what is the exact problem still ? And why linux/sched.h ?

Did you properly build kernel headers before building selftests ?

Quoted 22 lines
---
  tools/testing/selftests/vDSO/vdso_test_getrandom.c | 2 ++
  1 file changed, 2 insertions(+)
tools/testing/selftests/vDSO/vdso_test_getrandom.c +2 -1
index 95057f7567db..b2c9cf15878b 100644
@@ -29,6 +29,8 @@
  #include "vdso_config.h"
  #include "vdso_call.h"
 
+#include <linux/sched.h>
+
  #ifndef timespecsub
  #define        timespecsub(tsp, usp, vsp)                                      \
         do {                                                            \
--

2.34.1

#2 lore raw
Quoted 5 lines · Christophe Leroy

Le 26/01/2025 à 11:59, Purva Yeshi a écrit :

Quoted 2 lines

[Vous ne recevez pas souvent de courriers de [email protected]. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ]

Quoted 7 lines
Quoted 3 lines

Fix the build failure caused by the undefined CLONE_NEWTIME. Include the linux/sched.h header file where the function is defined to ensure successful compilation of the selftests.

This is supposed to be already fixed by commit 34d5b600172b ("selftests: vDSO: Explicitly include sched.h")

Can you explain what is the exact problem still ? And why linux/sched.h ?

Yes, I noticed that sched.h is already included, but I still encountered an "undeclared CLONE_NEWTIME" error during compilation.

Error I got:
CC vdso_test_getrandom
vdso_test_getrandom.c: In function ‘kselftest’:
vdso_test_getrandom.c:257:29: error: ‘CLONE_NEWTIME’ undeclared (first use in this function); did you mean ‘CLONE_NEWPID’?
257 | ksft_assert(unshare(CLONE_NEWTIME) == 0);
| ^~~~~
vdso_test_getrandom.c:47:20: note: in definition of macro ‘ksft_assert’
47 | do { if (!(condition)) ksft_exit_fail_msg("Assertion
failed: %s\n", #condition); } while (0)
| ^~~~~
vdso_test_getrandom.c:257:29: note: each undeclared identifier is reported only once for each function it appears in
257 | ksft_assert(unshare(CLONE_NEWTIME) == 0);
| ^~~~~
vdso_test_getrandom.c:47:20: note: in definition of macro ‘ksft_assert’
47 | do { if (!(condition)) ksft_exit_fail_msg("Assertion
failed: %s\n", #condition); } while (0)
| ^~~~~
make[1]: * [../lib.mk:222: /home/purva/linux/tools/testing/selftests/vDSO/vdso_test_getrandom] Error 1 make[1]: Leaving directory '/home/purva/linux/tools/testing/selftests/vDSO'

I found that CLONE_NEWTIME is declared in both sched.h and linux/sched.h. Since sched.h was already included, it was surprising that the error persisted. Adding linux/sched.h as a header resolved the issue, and the selftests compiled successfully after that.

Quoted 2 lines

Did you properly build kernel headers before building selftests ?

Yes, I ensured that I properly built the kernel headers before building the selftests by following the documentation provided here (https://docs.kernel.org/dev-tools/kselftest.html#running-the-selftests-hotplug-tests-are-run-in-limited-mode). I used the 'make headers' command as part of the process.

Quoted 16 lines
Quoted 16 lines

---
  tools/testing/selftests/vDSO/vdso_test_getrandom.c | 2 ++

  1 file changed, 2 insertions(+)
tools/testing/selftests/vDSO/vdso_test_getrandom.c +0 -0
index 95057f7567db..b2c9cf15878b 100644
@@ -29,6 +29,8 @@
   #include "vdso_config.h"
   #include "vdso_call.h"
 
Quoted 9 lines
Quoted 8 lines
tools/testing/selftests/vDSO/vdso_test_getrandom.c +2 -0
+#include <linux/sched.h>
+
   #ifndef timespecsub
   #define        timespecsub(tsp, usp, vsp)                                      \
          do {                                                            \
Signature · 1 line
2.34.1

Let me know if there’s anything further you'd like me to verify or adjust.

Thank you for your time and feedback!

Best regards,
Purva Yeshi

#3 lore raw

Le 29/01/2025 à 19:17, Purva Yeshi a écrit :

Quoted 13 lines · Christophe Leroy
Quoted 11 lines · Purva Yeshi
Quoted 7 lines

[Vous ne recevez pas souvent de courriers de [email protected]. Découvrez pourquoi ceci est important à
https://aka.ms/LearnAboutSenderIdentification ]

Fix the build failure caused by the undefined CLONE_NEWTIME. Include the linux/sched.h header file where the function is defined to ensure successful compilation of the selftests.

Quoted 7 lines
Quoted 4 lines

This is supposed to be already fixed by commit 34d5b600172b ("selftests:
vDSO: Explicitly include sched.h")

Can you explain what is the exact problem still ? And why linux/sched.h ?

Yes, I noticed that sched.h is already included, but I still encountered an "undeclared CLONE_NEWTIME" error during compilation.

Must be that your sched.h is not up-to-date I guess. On my side I have:

/usr/include/linux/sched.h:#define CLONE_NEWTIME 0x00000080 /* New time namespace */
/usr/include/bits/sched.h:#define CLONE_NEWTIME 0x00000080 /* New time namespace */

And

/usr/include/sched.h:#include <bits/sched.h>

Quoted 24 lines

Error I got:
CC       vdso_test_getrandom
vdso_test_getrandom.c: In function ‘kselftest’:
vdso_test_getrandom.c:257:29: error: ‘CLONE_NEWTIME’ undeclared (first use in this function); did you mean ‘CLONE_NEWPID’?
  257 |         ksft_assert(unshare(CLONE_NEWTIME) == 0);
      |                             ^~~~~
vdso_test_getrandom.c:47:20: note: in definition of macro ‘ksft_assert’
   47 |         do { if (!(condition)) ksft_exit_fail_msg("Assertion
failed: %s\n", #condition); } while (0)
      |                    ^~~~~
vdso_test_getrandom.c:257:29: note: each undeclared identifier is reported only once for each function it appears in
  257 |         ksft_assert(unshare(CLONE_NEWTIME) == 0);
      |                             ^~~~~
vdso_test_getrandom.c:47:20: note: in definition of macro ‘ksft_assert’
   47 |         do { if (!(condition)) ksft_exit_fail_msg("Assertion
failed: %s\n", #condition); } while (0)
      |                    ^~~~~
make[1]: * [../lib.mk:222:
/home/purva/linux/tools/testing/selftests/vDSO/vdso_test_getrandom] Error 1 make[1]: Leaving directory '/home/purva/linux/tools/testing/selftests/vDSO'

Quoted 4 lines

I found that CLONE_NEWTIME is declared in both sched.h and linux/sched.h. Since sched.h was already included, it was surprising that the error persisted. Adding linux/sched.h as a header resolved the issue, and the selftests compiled successfully after that.

Can you recheck that the sched.h that contains CLONE_NEWTIME is really the one used by your compiler ?

Quoted 6 lines
Quoted 3 lines

Did you properly build kernel headers before building selftests ?

Yes, I ensured that I properly built the kernel headers before building the selftests by following the documentation provided here

At the end we should probably wonder if we want selftests to build with old libc's that do not include latest defines. If we want to, then you should probably replace sched.h by linux/sched.h . I'm not sure about what to do really.

#4 lore raw
Quoted 58 lines · Christophe Leroy

Le 29/01/2025 à 19:17, Purva Yeshi a écrit :

Quoted 13 lines · Christophe Leroy
Quoted 11 lines · Purva Yeshi
Quoted 7 lines

[Vous ne recevez pas souvent de courriers de [email protected]. Découvrez pourquoi ceci est important à
https://aka.ms/LearnAboutSenderIdentification ]

Fix the build failure caused by the undefined CLONE_NEWTIME. Include the linux/sched.h header file where the function is defined to ensure successful compilation of the selftests.

Quoted 7 lines
Quoted 4 lines

This is supposed to be already fixed by commit 34d5b600172b ("selftests:
vDSO: Explicitly include sched.h")

Can you explain what is the exact problem still ? And why linux/sched.h ?

Yes, I noticed that sched.h is already included, but I still encountered an "undeclared CLONE_NEWTIME" error during compilation.

Must be that your sched.h is not up-to-date I guess. On my side I have:

/usr/include/linux/sched.h:#define CLONE_NEWTIME    0x00000080    /* New time namespace */ /usr/include/bits/sched.h:#define CLONE_NEWTIME    0x00000080      /* New time namespace */

And

/usr/include/sched.h:#include <bits/sched.h>

Quoted 24 lines

Error I got:
CC       vdso_test_getrandom
vdso_test_getrandom.c: In function ‘kselftest’:
vdso_test_getrandom.c:257:29: error: ‘CLONE_NEWTIME’ undeclared (first use in this function); did you mean ‘CLONE_NEWPID’?
   257 |         ksft_assert(unshare(CLONE_NEWTIME) == 0);
       |                             ^~~~~ vdso_test_getrandom.c:47:20: note: in definition of macro ‘ksft_assert’ 47 |         do { if (!(condition)) ksft_exit_fail_msg("Assertion
failed: %s\n", #condition); } while (0)
       |                    ^~~~~
vdso_test_getrandom.c:257:29: note: each undeclared identifier is reported only once for each function it appears in
   257 |         ksft_assert(unshare(CLONE_NEWTIME) == 0);
       |                             ^~~~~ vdso_test_getrandom.c:47:20: note: in definition of macro ‘ksft_assert’ 47 |         do { if (!(condition)) ksft_exit_fail_msg("Assertion
failed: %s\n", #condition); } while (0)
       |                    ^~~~~
make[1]: * [../lib.mk:222:
/home/purva/linux/tools/testing/selftests/vDSO/vdso_test_getrandom] Error 1 make[1]: Leaving directory '/home/purva/linux/tools/testing/selftests/vDSO'

Quoted 6 lines
Quoted 4 lines

I found that CLONE_NEWTIME is declared in both sched.h and linux/sched.h. Since sched.h was already included, it was surprising that the error persisted. Adding linux/sched.h as a header resolved the issue, and the selftests compiled successfully after that.

Can you recheck that the sched.h that contains CLONE_NEWTIME is really the one used by your compiler ?

I rechecked the header files on my system and got the following output:

purva@purva-IdeaPad-Gaming-3-15IHU6:~/linux$ grep -r "CLONE_NEWTIME" /usr/include/linux/sched.h /usr/include/bits/sched.h /usr/include/sched.h
/usr/include/linux/sched.h:#define CLONE_NEWTIME	0x00000080	/* New time namespace */

This shows that the definition of CLONE_NEWTIME exists only in /usr/include/linux/sched.h

Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

Did you properly build kernel headers before building selftests ?

Yes, I ensured that I properly built the kernel headers before building the selftests by following the documentation provided here

At the end we should probably wonder if we want selftests to build with old libc's that do not include latest defines. If we want to, then you should probably replace sched.h by linux/sched.h . I'm not sure about what to do really.

Since sched.h from libc may not define CLONE_NEWTIME on older systems, should we explicitly include linux/sched.h to ensure compatibility with older libc versions?

Thank you for your time and feedback!

Best regards,
Purva Yeshi

#5 lore raw
In reply to Christophe Leroy
Quoted 7 lines · Christophe Leroy
Quoted 4 lines · Purva Yeshi

[Vous ne recevez pas souvent de courriers de [email protected]. Découvrez pourquoi ceci est important à
https://aka.ms/LearnAboutSenderIdentification ]

Quoted 8 lines
Quoted 3 lines

Fix the build failure caused by the undefined CLONE_NEWTIME. Include the linux/sched.h header file where the function is defined to ensure successful compilation of the selftests.

This is supposed to be already fixed by commit 34d5b600172b ("selftests:
vDSO: Explicitly include sched.h")

Can you explain what is the exact problem still ? And why linux/sched.h ?

Yes, I noticed that sched.h is already included, but I still encountered an "undeclared CLONE_NEWTIME" error during compilation.

Error I got:
CC vdso_test_getrandom
vdso_test_getrandom.c: In function ‘kselftest’:
vdso_test_getrandom.c:257:29: error: ‘CLONE_NEWTIME’ undeclared (first use in this function); did you mean ‘CLONE_NEWPID’?
257 | ksft_assert(unshare(CLONE_NEWTIME) == 0);
| ^~~~~
vdso_test_getrandom.c:47:20: note: in definition of macro ‘ksft_assert’
47 | do { if (!(condition)) ksft_exit_fail_msg("Assertion
failed: %s\n", #condition); } while (0)
| ^~~~~
vdso_test_getrandom.c:257:29: note: each undeclared identifier is reported only once for each function it appears in
257 | ksft_assert(unshare(CLONE_NEWTIME) == 0);
| ^~~~~
vdso_test_getrandom.c:47:20: note: in definition of macro ‘ksft_assert’
47 | do { if (!(condition)) ksft_exit_fail_msg("Assertion
failed: %s\n", #condition); } while (0)
| ^~~~~
make[1]: * [../lib.mk:222:
/home/purva/linux/tools/testing/selftests/vDSO/vdso_test_getrandom] Error 1 make[1]: Leaving directory '/home/purva/linux/tools/testing/selftests/vDSO'

Quoted 30 lines

Did you properly build kernel headers before building selftests ?

Quoted 25 lines
---
  tools/testing/selftests/vDSO/vdso_test_getrandom.c | 2 ++
  1 file changed, 2 insertions(+)
tools/testing/selftests/vDSO/vdso_test_getrandom.c +2 -0
index 95057f7567db..b2c9cf15878b 100644
@@ -29,6 +29,8 @@
  #include "vdso_config.h"
  #include "vdso_call.h"
 
+#include <linux/sched.h>
+
  #ifndef timespecsub
  #define        timespecsub(tsp, usp,
 vsp)                                      \

do
{ \
--
2.34.1