Skip to contentSkip to conversation

selftests: vDSO: don't include generated headers for chacha test

PATCH Superseded Jason A. Donenfeld 4 participants 11 messages Sep 4, 2024 – Sep 11, 2024

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

PATCH 1/1 selftests: vDSO: don't include generated headers for chacha test

It's not correct to use $(top_srcdir) for generated header files, for builds that are done out of tree via O=, and $(objtree) isn't valid in the selftests context. Instead, just obviate the need for these generated header files by defining empty stubs in tools/include/asm, which is the same thing that's done for rwlock.h.

---
 tools/include/asm/asm-offsets.h       | 0
 tools/include/asm/cpucap-defs.h       | 0
 tools/include/asm/sysreg-defs.h       | 0
 tools/testing/selftests/vDSO/Makefile | 1 -
 4 files changed, 1 deletion(-)
 create mode 100644 tools/include/asm/asm-offsets.h
 create mode 100644 tools/include/asm/cpucap-defs.h
 create mode 100644 tools/include/asm/sysreg-defs.h
tools/include/asm/asm-offsets.h new file +0 -0
new file mode 100644
index 000000000000..e69de29bb2d1
tools/include/asm/cpucap-defs.h new file +0 -0
new file mode 100644
index 000000000000..e69de29bb2d1
tools/include/asm/sysreg-defs.h new file +0 -0
new file mode 100644
index 000000000000..e69de29bb2d1
tools/testing/selftests/vDSO/Makefile +0 -1
index 3c6fafbd83a6..55038a65fa61 100644
@@ -40,6 +40,5 @@ $(OUTPUT)/vdso_test_getrandom: CFLAGS += -isystem $(top_srcdir)/tools/include \
 $(OUTPUT)/vdso_test_chacha: $(top_srcdir)/tools/arch/$(SRCARCH)/vdso/vgetrandom-chacha.S
 $(OUTPUT)/vdso_test_chacha: CFLAGS += -idirafter $(top_srcdir)/tools/include \
                                       -idirafter $(top_srcdir)/arch/$(SRCARCH)/include \
-                                      -idirafter $(top_srcdir)/arch/$(SRCARCH)/include/generated \
                                       -idirafter $(top_srcdir)/include \
                                       -D__ASSEMBLY__ -Wa,--noexecstack
Signature · 1 line
2.46.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Jason A. Donenfeld

It's not correct to use $(top_srcdir) for generated header files, for builds that are done out of tree via O=, and $(objtree) isn't valid in the selftests context. Instead, just obviate the need for these generated header files by defining empty stubs in tools/include/asm, which is the same thing that's done for rwlock.h.

Works for me, thanks.

Quoted 30 lines
---
 tools/include/asm/asm-offsets.h       | 0
 tools/include/asm/cpucap-defs.h       | 0
 tools/include/asm/sysreg-defs.h       | 0
 tools/testing/selftests/vDSO/Makefile | 1 -
 4 files changed, 1 deletion(-)
 create mode 100644 tools/include/asm/asm-offsets.h
 create mode 100644 tools/include/asm/cpucap-defs.h
 create mode 100644 tools/include/asm/sysreg-defs.h
tools/include/asm/asm-offsets.h new file +0 -0
new file mode 100644
index 000000000000..e69de29bb2d1
tools/include/asm/cpucap-defs.h new file +0 -0
new file mode 100644
index 000000000000..e69de29bb2d1
tools/include/asm/sysreg-defs.h new file +0 -0
new file mode 100644
index 000000000000..e69de29bb2d1
tools/testing/selftests/vDSO/Makefile +0 -1
index 3c6fafbd83a6..55038a65fa61 100644
@@ -40,6 +40,5 @@ $(OUTPUT)/vdso_test_getrandom: CFLAGS += -isystem $(top_srcdir)/tools/include \
 $(OUTPUT)/vdso_test_chacha: $(top_srcdir)/tools/arch/$(SRCARCH)/vdso/vgetrandom-chacha.S
 $(OUTPUT)/vdso_test_chacha: CFLAGS += -idirafter $(top_srcdir)/tools/include \
                                       -idirafter $(top_srcdir)/arch/$(SRCARCH)/include \
-                                      -idirafter $(top_srcdir)/arch/$(SRCARCH)/include/generated \
                                       -idirafter $(top_srcdir)/include \
                                       -D__ASSEMBLY__ -Wa,--noexecstack
#2 lore raw
In reply to Jason A. Donenfeld
Quoted 7 lines · Jason A. Donenfeld

It's not correct to use $(top_srcdir) for generated header files, for builds that are done out of tree via O=, and $(objtree) isn't valid in the selftests context. Instead, just obviate the need for these generated header files by defining empty stubs in tools/include/asm, which is the same thing that's done for rwlock.h.

Hi Jason,

Currently when building kselftest against next-master with arm64 arch and defconfig+kselftest-kvm, few errors due to undeclared variables are observed in our CI. Hence unable to build and run kselftest-kvm tests.

I ran a bisect that pointed at this patch. I have attached the bisect log and full log from failure below.

Failure log:
-----------
https://storage.kernelci.org/next/master/next-20240906/arm64/defconfig+kselftest/gcc-12/logs/kselftest.log

In file included from /tmp/kci/linux/build/usr/include/linux/kvm.h:15,

                 from include/kvm_util.h:14,
                 from aarch64/aarch32_id_regs.c:13:
aarch64/aarch32_id_regs.c:70:27: error: ‘SYS_ID_PFR0_EL1’ undeclared
here (not in a function); did you mean ‘SYS_ICC_AP1R0_EL1’?
   70 |         KVM_ARM64_SYS_REG(SYS_ID_PFR0_EL1),
      |                           ^~~~~~~~~~~~~~~

.
.
aarch64/aarch32_id_regs.c:149:44: error: ‘ID_AA64PFR0_EL1_EL0_MASK’ undeclared (first use in this function)
149 | el0 = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_EL0),

val);
      |                                            ^~~~~~~~~~~~~~~~~~~
/tmp/kci/linux/tools/testing/selftests/../../../tools/include/linux/compiler.h:17:23:
note: in definition of macro ‘__compiletime_assert’
   17 |                 if (!(condition))
       \
      |                       ^~~~~~~~~

/tmp/kci/linux/tools/testing/selftests/../../../tools/include/linux/compiler.h:37:9:
note: in expansion of macro ‘_compiletime_assert’
37 | _compiletime_assert(condition, msg,
__compiletime_assert_, __COUNTER__)

      |         ^~~~~~~~~~~~~~~~~~~
/tmp/kci/linux/tools/testing/selftests/../../../tools/include/linux/build_bug.h:39:37:
note: in expansion of macro ‘compiletime_assert’
   39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
      |                                     ^~~~~~~~~~~~~~~~~~
/tmp/kci/linux/tools/testing/selftests/../../../tools/include/linux/bitfield.h:62:17:
note: in expansion of macro ‘BUILD_BUG_ON_MSG’
   62 |                 BUILD_BUG_ON_MSG(!__builtin_constant_p(_mask),
       \
      |                 ^~~~~~~~~~~~~~~~
/tmp/kci/linux/tools/testing/selftests/../../../tools/include/linux/bitfield.h:125:17:
note: in expansion of macro ‘__BF_FIELD_CHECK’
  125 |                 __BF_FIELD_CHECK(_mask, _reg, 0U, "FIELD_GET:
");       \
      |                 ^~~~~~~~~~~~~~~~
aarch64/aarch32_id_regs.c:149:15: note: in expansion of macro ‘FIELD_GET’
  149 |         el0 = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_EL0),
val);
      |               ^~~~~~~~~
aarch64/aarch32_id_regs.c:149:25: note: in expansion of macro
‘ARM64_FEATURE_MASK’
  149 |         el0 = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_EL0),
val);
      |                         ^~~~~~~~~~~~~~~~~~

At top level:
cc1: note: unrecognized command-line option ‘-Wno-gnu-variable-sized-type-not-at-end’ may have been intended to silence earlier diagnostics
make[4]: *** [Makefile:299:
/tmp/kci/linux/build/kselftest/kvm/aarch64/aarch32_id_regs.o] Error 1 make[4]: Leaving directory '/tmp/kci/linux/tools/testing/selftests/kvm'

Bisect log:
-----------
git bisect start
# good: [da3ea35007d0af457a0afc87e84fddaebc4e0b63] Linux 6.11-rc7 git bisect good da3ea35007d0af457a0afc87e84fddaebc4e0b63
# bad: [6708132e80a2ced620bde9b9c36e426183544a23] Add linux-next specific files for 20240910
git bisect bad 6708132e80a2ced620bde9b9c36e426183544a23
# good: [b66d58fce82c825b3dbb57a46b9a74f081ef7ec7] Merge branch 'main' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git
git bisect good b66d58fce82c825b3dbb57a46b9a74f081ef7ec7
# good: [a636a90415dbc59f005369e3053996f859f0af50] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/libata/linux
git bisect good a636a90415dbc59f005369e3053996f859f0af50
# good: [8e5ac35ddecbeddce79e915c226baaf577a2be6e] Merge branch 'driver-core-next' of
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git
git bisect good 8e5ac35ddecbeddce79e915c226baaf577a2be6e
# good: [e9643b5e3a2f5f0607d3b71bebe22cc6d29b534c] Merge branch 'counter-next' of
git://git.kernel.org/pub/scm/linux/kernel/git/wbg/counter.git
git bisect good e9643b5e3a2f5f0607d3b71bebe22cc6d29b534c
# good: [150b9788d677f54650e1aceffde0eead5986baab] Merge branch 'pwm/for-next' of
git://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git
git bisect good 150b9788d677f54650e1aceffde0eead5986baab
# good: [b4c533038255b85a068b622f888e0a9e8096a199] Merge branch 'slab/for-next' of
git://git.kernel.org/pub/scm/linux/kernel/git/vbabka/slab.git
git bisect good b4c533038255b85a068b622f888e0a9e8096a199
# bad: [b9a71f4a0f68d11be247fd7ff82d7a72e3503181] Merge branch 'rust-next' of https://github.com/Rust-for-Linux/linux.git
git bisect bad b9a71f4a0f68d11be247fd7ff82d7a72e3503181
# good: [aeb0e24abbebebff3b5ac65486c933d0ecd5cf81] kbuild: rust: replace proc macros dependency on core.o with the version text
git bisect good aeb0e24abbebebff3b5ac65486c933d0ecd5cf81
# good: [b75eb4403eefde26f8f71a66dcc609a091fa40e6] random: vDSO:
minimize and simplify header includes
git bisect good b75eb4403eefde26f8f71a66dcc609a091fa40e6
# bad: [5bc8fca346995ada9a379369492620f5d1991a08] powerpc/vdso32: Add crtsavres
git bisect bad 5bc8fca346995ada9a379369492620f5d1991a08
# good: [c2066b95688ab8d1c296d44e325f54630688e6a7] selftests: vDSO: also test counter in vdso_test_chacha
git bisect good c2066b95688ab8d1c296d44e325f54630688e6a7
# bad: [a727d213f81c9ffba79e161f59e120c92b9ddb1b] selftests: vDSO: don't include generated headers for chacha test
git bisect bad a727d213f81c9ffba79e161f59e120c92b9ddb1b
# good: [67e5214e51e767d4e04d9eb5754d320c918c5ed8] arm64: vDSO: Wire up getrandom() vDSO implementation
git bisect good 67e5214e51e767d4e04d9eb5754d320c918c5ed8

# first bad commit: [a727d213f81c9ffba79e161f59e120c92b9ddb1b]
selftests: vDSO: don't include generated headers for chacha test

Thanks,
Aishwarya

#3 lore raw
Quoted 3 lines · Aishwarya TCV

make[4]: *** [Makefile:299:
/tmp/kci/linux/build/kselftest/kvm/aarch64/aarch32_id_regs.o] Error 1 make[4]: Leaving directory '/tmp/kci/linux/tools/testing/selftests/kvm'

You sure this bisected right? That directory isn't related to the commit in question, I don't think...

Jason

#4 lore raw
Quoted 7 lines · Jason A. Donenfeld
Quoted 3 lines · Aishwarya TCV

make[4]: *** [Makefile:299:
/tmp/kci/linux/build/kselftest/kvm/aarch64/aarch32_id_regs.o] Error 1 make[4]: Leaving directory '/tmp/kci/linux/tools/testing/selftests/kvm'

You sure this bisected right? That directory isn't related to the commit in question, I don't think...

I eyeballed it for Aishwarya and it looked related on first glance (messing around with the generated headers), though looking again it's only in the vDSO directory so shouldn't be messing up other directories...

#5 lore raw
Quoted 6 lines · Mark Brown
Quoted 4 lines · Jason A. Donenfeld
Quoted 3 lines · Aishwarya TCV

make[4]: *** [Makefile:299:
/tmp/kci/linux/build/kselftest/kvm/aarch64/aarch32_id_regs.o] Error 1 make[4]: Leaving directory '/tmp/kci/linux/tools/testing/selftests/kvm'

Quoted 7 lines
Quoted 2 lines

You sure this bisected right? That directory isn't related to the commit in question, I don't think...

I eyeballed it for Aishwarya and it looked related on first glance (messing around with the generated headers), though looking again it's only in the vDSO directory so shouldn't be messing up other directories...

Okay, so... I reproduced the problem on linux-next. Then I reverted the commit and reproduced it again. Then just to be sure, I ran:

    $ git checkout v6.9 tools/testing/selftests/vDSO/

And then I reproduced the problem again.

So I think we can be somewhat certain the unrelated directory is indeed unrelated.

#6 lore raw
Quoted 18 lines · Jason A. Donenfeld
Quoted 6 lines · Mark Brown
Quoted 4 lines · Jason A. Donenfeld
Quoted 3 lines · Aishwarya TCV

make[4]: *** [Makefile:299:
/tmp/kci/linux/build/kselftest/kvm/aarch64/aarch32_id_regs.o] Error 1 make[4]: Leaving directory '/tmp/kci/linux/tools/testing/selftests/kvm'

Quoted 7 lines
Quoted 2 lines

You sure this bisected right? That directory isn't related to the commit in question, I don't think...

I eyeballed it for Aishwarya and it looked related on first glance (messing around with the generated headers), though looking again it's only in the vDSO directory so shouldn't be messing up other directories...

Okay, so... I reproduced the problem on linux-next. Then I reverted the commit and reproduced it again. Then just to be sure, I ran:

Quoted 6 lines
    $ git checkout v6.9 tools/testing/selftests/vDSO/

And then I reproduced the problem again.

So I think we can be somewhat certain the unrelated directory is indeed unrelated.

Ahhh, got it.

Running $ rm tools/include/asm/sysreg-defs.h fixes the problem. I'll look into a fix this afternoon.

Jason

#7 lore raw
Quoted 23 lines · Jason A. Donenfeld
Quoted 22 lines · Jason A. Donenfeld
Quoted 6 lines · Mark Brown
Quoted 4 lines · Jason A. Donenfeld
Quoted 3 lines · Aishwarya TCV

make[4]: *** [Makefile:299:
/tmp/kci/linux/build/kselftest/kvm/aarch64/aarch32_id_regs.o] Error 1 make[4]: Leaving directory '/tmp/kci/linux/tools/testing/selftests/kvm'

Quoted 7 lines
Quoted 2 lines

You sure this bisected right? That directory isn't related to the commit in question, I don't think...

I eyeballed it for Aishwarya and it looked related on first glance (messing around with the generated headers), though looking again it's only in the vDSO directory so shouldn't be messing up other directories...

Okay, so... I reproduced the problem on linux-next. Then I reverted the commit and reproduced it again. Then just to be sure, I ran:

    $ git checkout v6.9 tools/testing/selftests/vDSO/

And then I reproduced the problem again.

Quoted 7 lines
Quoted 2 lines

So I think we can be somewhat certain the unrelated directory is indeed unrelated.

Ahhh, got it.

Running $ rm tools/include/asm/sysreg-defs.h fixes the problem. I'll look into a fix this afternoon.

I'll fix it up as follows:

tools/include/generated/asm-offsets.h renamed from tools/include/asm/asm-offsets.h +0 -0
similarity index 100%
rename from tools/include/asm/asm-offsets.h
rename to tools/include/generated/asm-offsets.h
tools/include/generated/asm/cpucap-defs.h renamed from tools/include/asm/cpucap-defs.h +0 -0
similarity index 100%
rename from tools/include/asm/cpucap-defs.h
rename to tools/include/generated/asm/cpucap-defs.h
tools/include/generated/asm/sysreg-defs.h renamed from tools/include/asm/sysreg-defs.h +0 -0
similarity index 100%
rename from tools/include/asm/sysreg-defs.h
rename to tools/include/generated/asm/sysreg-defs.h
tools/testing/selftests/vDSO/Makefile +1 -0
index 5bd30d745d42..86ebc4115eda 100644
@@ -39,6 +39,7 @@ $(OUTPUT)/vdso_test_getrandom: CFLAGS += -isystem $(top_srcdir)/tools/include \
 
 $(OUTPUT)/vdso_test_chacha: $(top_srcdir)/tools/arch/$(SRCARCH)/vdso/vgetrandom-chacha.S
 $(OUTPUT)/vdso_test_chacha: CFLAGS += -idirafter $(top_srcdir)/tools/include \
+                                      -idirafter $(top_srcdir)/tools/include/generated \
                                       -idirafter $(top_srcdir)/arch/$(SRCARCH)/include \
                                       -idirafter $(top_srcdir)/include \
                                       -D__ASSEMBLY__ -Wa,--noexecstack
#8 lore raw

PATCH v2 1/1 selftests: vDSO: don't include generated headers for chacha test

It's not correct to use $(top_srcdir) for generated header files, for builds that are done out of tree via O=, and $(objtree) isn't valid in the selftests context. Instead, just obviate the need for these generated header files by defining empty stubs in tools/include, which is the same thing that's done for rwlock.h.

---
I'll replace the broken commit with this one. I've verified the kselftests are fine now, particularly for kvm.

 tools/include/generated/asm-offsets.h     | 0
 tools/include/generated/asm/cpucap-defs.h | 0
 tools/include/generated/asm/sysreg-defs.h | 0
 tools/testing/selftests/vDSO/Makefile     | 2 +-
 4 files changed, 1 insertion(+), 1 deletion(-)
 create mode 100644 tools/include/generated/asm-offsets.h
 create mode 100644 tools/include/generated/asm/cpucap-defs.h
 create mode 100644 tools/include/generated/asm/sysreg-defs.h
tools/include/generated/asm-offsets.h new file +0 -0
new file mode 100644
index 000000000000..e69de29bb2d1
tools/include/generated/asm/cpucap-defs.h new file +0 -0
new file mode 100644
index 000000000000..e69de29bb2d1
tools/include/generated/asm/sysreg-defs.h new file +0 -0
new file mode 100644
index 000000000000..e69de29bb2d1
tools/testing/selftests/vDSO/Makefile +1 -1
index 3c6fafbd83a6..610056acc1b7 100644
@@ -39,7 +39,7 @@ $(OUTPUT)/vdso_test_getrandom: CFLAGS += -isystem $(top_srcdir)/tools/include \
 
 $(OUTPUT)/vdso_test_chacha: $(top_srcdir)/tools/arch/$(SRCARCH)/vdso/vgetrandom-chacha.S
 $(OUTPUT)/vdso_test_chacha: CFLAGS += -idirafter $(top_srcdir)/tools/include \
+                                      -idirafter $(top_srcdir)/tools/include/generated \
                                       -idirafter $(top_srcdir)/arch/$(SRCARCH)/include \
-                                      -idirafter $(top_srcdir)/arch/$(SRCARCH)/include/generated \
                                       -idirafter $(top_srcdir)/include \
                                       -D__ASSEMBLY__ -Wa,--noexecstack
Signature · 1 line
2.46.0
#9 lore raw
Quoted 5 lines · Jason A. Donenfeld

It's not correct to use $(top_srcdir) for generated header files, for builds that are done out of tree via O=, and $(objtree) isn't valid in the selftests context. Instead, just obviate the need for these generated header files by defining empty stubs in tools/include, which is the same thing that's done for rwlock.h.

...

Quoted 2 lines

I'll replace the broken commit with this one. I've verified the kselftests are fine now, particularly for kvm.

Did you also check perf? For arm64 it uses the sysregs values though I don't off hand know if that includes any of the generated values. I would expect that KVM will start breaking for arm64 at some point even if it works for now, there was a desire to replace use of magic numbers for registers in the tests with defines.

#10 lore raw
Quoted 10 lines · Mark Brown
Quoted 5 lines · Jason A. Donenfeld

It's not correct to use $(top_srcdir) for generated header files, for builds that are done out of tree via O=, and $(objtree) isn't valid in the selftests context. Instead, just obviate the need for these generated header files by defining empty stubs in tools/include, which is the same thing that's done for rwlock.h.

...

Quoted 8 lines
Quoted 2 lines

I'll replace the broken commit with this one. I've verified the kselftests are fine now, particularly for kvm.

Did you also check perf? For arm64 it uses the sysregs values though I don't off hand know if that includes any of the generated values. I would expect that KVM will start breaking for arm64 at some point even if it works for now, there was a desire to replace use of magic numbers for registers in the tests with defines.

I just booted an arm64 VM and built perf with all the various options and such, and it works fine. Those header files in the fixup commit aren't seen by perf.

Jason