1. 13 Sep, 2024 16 commits
    • Jason A. Donenfeld's avatar
      selftests: vDSO: don't include generated headers for chacha test · 8bc7c5e5
      Jason A. Donenfeld authored
      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.
      Reviewed-by: default avatarAdhemerval Zanella  <adhemerval.zanella@linaro.org>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      8bc7c5e5
    • Adhemerval Zanella's avatar
      arm64: vDSO: Wire up getrandom() vDSO implementation · 712676ea
      Adhemerval Zanella authored
      Hook up the generic vDSO implementation to the aarch64 vDSO data page.
      The _vdso_rng_data required data is placed within the _vdso_data vvar
      page, by using a offset larger than the vdso_data.
      
      The vDSO function requires a ChaCha20 implementation that does not write
      to the stack, and that can do an entire ChaCha20 permutation.  The one
      provided uses NEON on the permute operation, with a fallback to the
      syscall for chips that do not support AdvSIMD.
      
      This also passes the vdso_test_chacha test along with
      vdso_test_getrandom. The vdso_test_getrandom bench-single result on
      Neoverse-N1 shows:
      
         vdso: 25000000 times in 0.783884250 seconds
         libc: 25000000 times in 8.780275399 seconds
      syscall: 25000000 times in 8.786581518 seconds
      
      A small fixup to arch/arm64/include/asm/mman.h was required to avoid
      pulling kernel code into the vDSO, similar to what's already done in
      arch/arm64/include/asm/rwonce.h.
      Signed-off-by: default avatarAdhemerval Zanella <adhemerval.zanella@linaro.org>
      Reviewed-by: default avatarArd Biesheuvel <ardb@kernel.org>
      Acked-by: default avatarWill Deacon <will@kernel.org>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      712676ea
    • Mark Rutland's avatar
      arm64: alternative: make alternative_has_cap_likely() VDSO compatible · 2c2ca341
      Mark Rutland authored
      Currently alternative_has_cap_unlikely() can be used in VDSO code, but
      alternative_has_cap_likely() cannot as it references alt_cb_patch_nops,
      which is not available when linking the VDSO. This is unfortunate as it
      would be useful to have alternative_has_cap_likely() available in VDSO
      code.
      
      The use of alt_cb_patch_nops was added in commit:
      
        d926079f ("arm64: alternatives: add shared NOP callback")
      
      ... as removing duplicate NOPs within the kernel Image saved areasonable
      amount of space.
      
      Given the VDSO code will have nowhere near as many alternative branches
      as the main kernel image, this isn't much of a concern, and a few extra
      nops isn't a massive problem.
      
      Change alternative_has_cap_likely() to only use alt_cb_patch_nops for
      the main kernel image, and allow duplicate NOPs in VDSO code.
      Signed-off-by: default avatarMark Rutland <mark.rutland@arm.com>
      Signed-off-by: default avatarAdhemerval Zanella <adhemerval.zanella@linaro.org>
      Acked-by: default avatarWill Deacon <will@kernel.org>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      2c2ca341
    • Christophe Leroy's avatar
      selftests: vDSO: also test counter in vdso_test_chacha · bb10ffe0
      Christophe Leroy authored
      The chacha vDSO selftest doesn't check the way the counter is handled by
      __arch_chacha20_blocks_nostack(). It indirectly checks that the counter
      is writen on exit and read back on new entry, but it doesn't check that
      the format is correct. When implementing this function on powerpc, I
      missed a case where the counter was writen and read in wrong byte order.
      
      Also, the counter uses two words, but the tests with a zero counter and
      uses a small amount of blocks, so at the end the upper part of the
      counter is always 0, so it is not checked.
      
      Add a verification of counter's content in addition to the verification
      of the output.
      
      Also add two tests where the counter crosses the u32 upper limit. The
      first test verifies that the function properly writes back the upper
      word, the second test verifies that the function properly reads back the
      upper word.
      Signed-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      bb10ffe0
    • Christophe Leroy's avatar
      selftests: vDSO: build tests with O2 optimization · ecb8bd70
      Christophe Leroy authored
      Without -O2, the generated code for testing chacha function is awful.
      GCC even implements rol32() as a function of 20 instructions instead of
      just using the rotlwi instruction.
      
      	~# time ./vdso_test_chacha
      	TAP version 13
      	1..1
      	ok 1 chacha: PASS
      	real    0m 37.16s
      	user    0m 36.89s
      	sys     0m 0.26s
      
      Several other selftests directory add -O2, and the kernel is also
      always built with optimisation active. Do the same for vDSO selftests.
      
      With this patch the time is reduced by approximately 15%.
      
      	~# time ./vdso_test_chacha
      	TAP version 13
      	1..1
      	ok 1 chacha: PASS
      	real    0m 32.09s
      	user    0m 31.86s
      	sys     0m 0.22s
      Signed-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      ecb8bd70
    • Xi Ruoyao's avatar
      LoongArch: vDSO: Wire up getrandom() vDSO implementation · 18efd0b1
      Xi Ruoyao authored
      Hook up the generic vDSO implementation to the LoongArch vDSO data page
      by providing the required __arch_chacha20_blocks_nostack,
      __arch_get_k_vdso_rng_data, and getrandom_syscall implementations. Also
      wire up the selftests.
      Signed-off-by: default avatarXi Ruoyao <xry111@xry111.site>
      Acked-by: default avatarHuacai Chen <chenhuacai@kernel.org>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      18efd0b1
    • Xi Ruoyao's avatar
      random: vDSO: add a __vdso_getrandom prototype for all architectures · 4d456f0c
      Xi Ruoyao authored
      Without a prototype, we'll have to add a prototype for each architecture
      implementing vDSO getrandom. As most architectures will likely have the
      vDSO getrandom implemented in a near future, and we'd like to keep the
      declarations compatible everywhere (to ease the libc implementor work),
      we should really just have one copy of the prototype.
      
      This also is what's already done inside of include/vdso/gettime.h for
      those vDSO functions, so this continues that convention.
      Suggested-by: default avatarHuacai Chen <chenhuacai@kernel.org>
      Signed-off-by: default avatarXi Ruoyao <xry111@xry111.site>
      Acked-by: default avatarHuacai Chen <chenhuacai@kernel.org>
      [Jason: rewrite docbook comment for prototype.]
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      4d456f0c
    • Jason A. Donenfeld's avatar
      selftests: vDSO: fix cross build for getrandom and chacha tests · 67a121ac
      Jason A. Donenfeld authored
      Unlike the check for the standalone x86 test, the check for building the
      vDSO getrandom and chacaha tests looks at the architecture for the host
      rather than the architecture for the target when deciding if they should
      be built. Since the chacha test includes some assembler code this means
      that cross building with x86 as either the target or host is broken.
      
      There's also some additional complications, where ARCH can legitimately
      be either x86_64 or x86, but the source code we need to compile lives in
      a directory path containing arch/x86. The standard SRCARCH variable
      handles that. And actually, all these variables and proper substitutions
      are already described in tools/scripts/Makefile.arch, so just include
      that to handle it.
      
      Similarly, ARCH=x86 can actually describe ARCH=x86_64,
      just with CONFIG_64BIT, so we can't rely on ARCH for selecting
      non-32-bit tests. For that, check against $(ARCH)$(CONFIG_X86_32). This
      won't help for people manually running this inside the vDSO selftest
      directory (which isn't really supported anyway and has problems on
      various archs), but it should work for builds of the kselftests, where
      the CONFIG_* variables are defined. On x86_64 machines,
      $(ARCH)$(CONFIG_X86_32) will evaluate to x86. On arm64 machines, it will
      evaluate to arm64. On 32-bit x86 machines, it will evaluate to x86y,
      which won't match the filter list.
      Reported-by: default avatarMark Brown <broonie@kernel.org>
      Reported-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      67a121ac
    • Christophe Leroy's avatar
      random: vDSO: minimize and simplify header includes · 7f053812
      Christophe Leroy authored
      Depending on the architecture, building a 32-bit vDSO on a 64-bit kernel
      is problematic when some system headers are included.
      
      Minimise the amount of headers by moving needed items, such as
      __{get,put}_unaligned_t, into dedicated common headers and in general
      use more specific headers, similar to what was done in commit
      8165b57b ("linux/const.h: Extract common header for vDSO") and
      commit 8c59ab83 ("lib/vdso: Enable common headers").
      
      On some architectures this results in missing PAGE_SIZE, as was
      described by commit 8b3843ae ("vdso/datapage: Quick fix - use
      asm/page-def.h for ARM64"), so define this if necessary, in the same way
      as done prior by commit cffaefd1 ("vdso: Use CONFIG_PAGE_SHIFT in
      vdso/datapage.h").
      
      Removing linux/time64.h leads to missing 'struct timespec64' in
      x86's asm/pvclock.h. Add a forward declaration of that struct in
      that file.
      Signed-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      7f053812
    • Christophe Leroy's avatar
      random: vDSO: avoid call to out of line memset() · b7bad082
      Christophe Leroy authored
      With the current implementation, __cvdso_getrandom_data() calls
      memset() on certain architectures, which is unexpected in the VDSO.
      
      Rather than providing a memset(), simply rewrite opaque data
      initialization to avoid memset().
      Signed-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
      Acked-by: default avatarArd Biesheuvel <ardb@kernel.org>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      b7bad082
    • Christophe Leroy's avatar
      random: vDSO: add missing c-getrandom-y in Makefile · 81723e3a
      Christophe Leroy authored
      Same as for the gettimeofday CVDSO implementation, add c-getrandom-y to
      ease the inclusion of lib/vdso/getrandom.c in architectures' VDSO
      builds.
      Signed-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      81723e3a
    • Christophe Leroy's avatar
      random: vDSO: add __arch_get_k_vdso_rng_data() helper for data page access · b757959f
      Christophe Leroy authored
      _vdso_data is specific to x86 and __arch_get_k_vdso_data() is provided
      so that all architectures can provide the requested pointer.
      
      Do the same with _vdso_rng_data, provide __arch_get_k_vdso_rng_data()
      and don't use x86 _vdso_rng_data directly.
      
      Until now vdso/vsyscall.h was only included by time/vsyscall.c but now
      it will also be included in char/random.c, leading to a duplicate
      declaration of _vdso_data and _vdso_rng_data.
      
      To fix this issue, move the declaration in a C file. vma.c looks like
      the most appropriate candidate. We don't need to replace the definitions
      in vsyscall.h by declarations as declarations are already in asm/vvar.h.
      Signed-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      b757959f
    • Christophe Leroy's avatar
      random: vDSO: don't use 64-bit atomics on 32-bit architectures · 81c68960
      Christophe Leroy authored
      Performing SMP atomic operations on u64 fails on powerpc32:
      
          CC      drivers/char/random.o
        In file included from <command-line>:
        drivers/char/random.c: In function 'crng_reseed':
        ././include/linux/compiler_types.h:510:45: error: call to '__compiletime_assert_391' declared with attribute error: Need native word sized stores/loads for atomicity.
          510 |         _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
              |                                             ^
        ././include/linux/compiler_types.h:491:25: note: in definition of macro '__compiletime_assert'
          491 |                         prefix ## suffix();                             \
              |                         ^~~~~~
        ././include/linux/compiler_types.h:510:9: note: in expansion of macro '_compiletime_assert'
          510 |         _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
              |         ^~~~~~~~~~~~~~~~~~~
        ././include/linux/compiler_types.h:513:9: note: in expansion of macro 'compiletime_assert'
          513 |         compiletime_assert(__native_word(t),                            \
              |         ^~~~~~~~~~~~~~~~~~
        ./arch/powerpc/include/asm/barrier.h:74:9: note: in expansion of macro 'compiletime_assert_atomic_type'
           74 |         compiletime_assert_atomic_type(*p);                             \
              |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ./include/asm-generic/barrier.h:172:55: note: in expansion of macro '__smp_store_release'
          172 | #define smp_store_release(p, v) do { kcsan_release(); __smp_store_release(p, v); } while (0)
              |                                                       ^~~~~~~~~~~~~~~~~~~
        drivers/char/random.c:286:9: note: in expansion of macro 'smp_store_release'
          286 |         smp_store_release(&__arch_get_k_vdso_rng_data()->generation, next_gen + 1);
              |         ^~~~~~~~~~~~~~~~~
      
      The kernel-side generation counter in the random driver is handled as an
      unsigned long, not as a u64, in base_crng and struct crng.
      
      But on the vDSO side, it needs to be an u64, not just an unsigned long,
      in order to support a 32-bit vDSO atop a 64-bit kernel.
      
      On kernel side, however, it is an unsigned long, hence a 32-bit value on
      32-bit architectures, so just cast it to unsigned long for the
      smp_store_release(). A side effect is that on big endian architectures
      the store will be performed in the upper 32 bits. It is not an issue on
      its own because the vDSO site doesn't mind the value, as it only checks
      differences. Just make sure that the vDSO side checks the full 64 bits.
      For that, the local current_generation has to be u64 as well.
      Signed-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
      Suggested-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      81c68960
    • Jason A. Donenfeld's avatar
      selftests: vDSO: open code basic chacha instead of linking to libsodium · 7fe5b3e4
      Jason A. Donenfeld authored
      Linking to libsodium makes building this test annoying in cross
      compilation environments and is just way too much. Since this is just a
      basic correctness test, simply open code a simple, unoptimized, dumb
      chacha, rather than linking to libsodium.
      
      This also fixes a correctness issue on big endian systems. The kernel's
      random.c doesn't bother doing a le32_to_cpu operation on the random
      bytes that are passed as the key, and consequently neither does
      vgetrandom-chacha.S. However, libsodium's chacha _does_ do this, since
      it takes the key as an array of bytes. This meant that the test was
      broken on big endian systems, which this commit rectifies.
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      7fe5b3e4
    • Jason A. Donenfeld's avatar
      random: vDSO: move prototype of arch chacha function to vdso/getrandom.h · 6fd13b28
      Jason A. Donenfeld authored
      Having the prototype for __arch_chacha20_blocks_nostack in
      arch/x86/include/asm/vdso/getrandom.h meant that the prototype and large
      doc comment were cloned by every architecture, which has been causing
      unnecessary churn. Instead move it into include/vdso/getrandom.h, where
      it can be shared by all archs implementing it.
      
      As a side bonus, this then lets us use that prototype in the
      vdso_test_chacha self test, to ensure that it matches the source, and
      indeed doing so turned up some inconsistencies, which are rectified
      here.
      Suggested-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      6fd13b28
    • Jason A. Donenfeld's avatar
      selftests: vDSO: ensure vgetrandom works in a time namespace · 2aec9003
      Jason A. Donenfeld authored
      After verifying that vDSO getrandom does work, which ensures that the
      RNG is initialized, test to see if it also works inside of a time
      namespace. This is important to test, because the vvar pages get
      swizzled around there. If the arch code isn't careful, the RNG will
      appear uninitialized inside of a time namespace.
      
      Because broken code makes the RNG appear uninitialized, test that
      everything works by issuing a call to vgetrandom from a fork in a time
      namespace, and use ptrace to ensure that the actual syscall getrandom
      doesn't get called. If it doesn't get called, then the test succeeds.
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      2aec9003
  2. 30 Aug, 2024 15 commits
    • Jason A. Donenfeld's avatar
      selftests: vDSO: quash clang omitted parameter warning in getrandom test · 33ffa2dd
      Jason A. Donenfeld authored
      When building with clang, there's this warning:
      
      vdso_test_getrandom.c:145:40: warning: omitting the parameter name in a function definition is a C23 extension [-Wc23-extensions]
        145 | static void *test_vdso_getrandom(void *)
            |                                        ^
      vdso_test_getrandom.c:155:40: warning: omitting the parameter name in a function definition is a C23 extension [-Wc23-extensions]
        155 | static void *test_libc_getrandom(void *)
            |                                        ^
      vdso_test_getrandom.c:165:43: warning: omitting the parameter name in a function definition is a C23 extension [-Wc23-extensions]
        165 | static void *test_syscall_getrandom(void *)
      
      Add the named ctx parameter to quash it.
      Reported-by: default avatarMark Brown <broonie@kernel.org>
      Reviewed-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      33ffa2dd
    • Christophe Leroy's avatar
      selftests: vDSO: use parse_vdso.h in vdso_test_abi · f0d0dbbc
      Christophe Leroy authored
      Don't duplicate parse_vdso function prototypes, include
      the header instead.
      
      Fixes: 693f5ca0 ("kselftest: Extend vDSO selftest")
      Signed-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
      Acked-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      f0d0dbbc
    • Christophe Leroy's avatar
      selftests: vDSO: fix the way vDSO functions are called for powerpc · 6eda706a
      Christophe Leroy authored
      vdso_test_correctness test fails on powerpc:
      
      ~ # ./vdso_test_correctness
      ...
      [RUN]	Testing clock_gettime for clock CLOCK_REALTIME_ALARM (8)...
      [FAIL]	No such clock, but __vdso_clock_gettime returned 22
      [RUN]	Testing clock_gettime for clock CLOCK_BOOTTIME_ALARM (9)...
      [FAIL]	No such clock, but __vdso_clock_gettime returned 22
      [RUN]	Testing clock_gettime for clock CLOCK_SGI_CYCLE (10)...
      [FAIL]	No such clock, but __vdso_clock_gettime returned 22
      ...
      [RUN]	Testing clock_gettime for clock invalid (-1)...
      [FAIL]	No such clock, but __vdso_clock_gettime returned 22
      [RUN]	Testing clock_gettime for clock invalid (-2147483648)...
      [FAIL]	No such clock, but __vdso_clock_gettime returned 22
      [RUN]	Testing clock_gettime for clock invalid (2147483647)...
      [FAIL]	No such clock, but __vdso_clock_gettime returned 22
      
      On powerpc, a call to a VDSO function is not an ordinary C function
      call. Unlike several architectures which returns a negative error code
      in case of an error, powerpc sets CR[SO] and returns the error code
      as a positive value.
      
      Define and use a macro called VDSO_CALL() which takes a pointer
      to the function to call, the number of arguments and the arguments.
      
      Also update ABI vdso documentation to reflect this subtlety.
      
      Provide a specific version of VDSO_CALL() for powerpc that negates
      the error code on return when CR[SO] is set.
      
      Fixes: c7e5789b ("kselftest: Move test_vdso to the vDSO test suite")
      Fixes: 2e9a9725 ("selftests: vdso: Add a selftest for vDSO getcpu()")
      Fixes: 693f5ca0 ("kselftest: Extend vDSO selftest")
      Fixes: b2f1c3db ("kselftest: Extend vdso correctness test to clock_gettime64")
      Fixes: 4920a259 ("selftests/vDSO: add tests for vgetrandom")
      Signed-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
      Acked-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      6eda706a
    • Christophe Leroy's avatar
      selftests: vDSO: fix vDSO symbols lookup for powerpc64 · ba83b323
      Christophe Leroy authored
      On powerpc64, following tests fail locating vDSO functions:
      
        ~ # ./vdso_test_abi
        TAP version 13
        1..16
        # [vDSO kselftest] VDSO_VERSION: LINUX_2.6.15
        # Couldn't find __kernel_gettimeofday
        ok 1 # SKIP __kernel_gettimeofday
        # clock_id: CLOCK_REALTIME
        # Couldn't find __kernel_clock_gettime
        ok 2 # SKIP __kernel_clock_gettime CLOCK_REALTIME
        # Couldn't find __kernel_clock_getres
        ok 3 # SKIP __kernel_clock_getres CLOCK_REALTIME
        ...
        # Couldn't find __kernel_time
        ok 16 # SKIP __kernel_time
        # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:16 error:0
      
        ~ # ./vdso_test_getrandom
        __kernel_getrandom is missing!
      
        ~ # ./vdso_test_gettimeofday
        Could not find __kernel_gettimeofday
      
        ~ # ./vdso_test_getcpu
        Could not find __kernel_getcpu
      
      On powerpc64, as shown below by readelf, vDSO functions symbols have
      type NOTYPE, so also accept that type when looking for symbols.
      
      $ powerpc64-linux-gnu-readelf -a arch/powerpc/kernel/vdso/vdso64.so.dbg
      ELF Header:
        Magic:   7f 45 4c 46 02 02 01 00 00 00 00 00 00 00 00 00
        Class:                             ELF64
        Data:                              2's complement, big endian
        Version:                           1 (current)
        OS/ABI:                            UNIX - System V
        ABI Version:                       0
        Type:                              DYN (Shared object file)
        Machine:                           PowerPC64
        Version:                           0x1
      ...
      
      Symbol table '.dynsym' contains 12 entries:
         Num:    Value          Size Type    Bind   Vis      Ndx Name
           0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
           1: 0000000000000524    84 NOTYPE  GLOBAL DEFAULT    8 __[...]@@LINUX_2.6.15
           2: 00000000000005f0    36 NOTYPE  GLOBAL DEFAULT    8 __[...]@@LINUX_2.6.15
           3: 0000000000000578    68 NOTYPE  GLOBAL DEFAULT    8 __[...]@@LINUX_2.6.15
           4: 0000000000000000     0 OBJECT  GLOBAL DEFAULT  ABS LINUX_2.6.15
           5: 00000000000006c0    48 NOTYPE  GLOBAL DEFAULT    8 __[...]@@LINUX_2.6.15
           6: 0000000000000614   172 NOTYPE  GLOBAL DEFAULT    8 __[...]@@LINUX_2.6.15
           7: 00000000000006f0    84 NOTYPE  GLOBAL DEFAULT    8 __[...]@@LINUX_2.6.15
           8: 000000000000047c    84 NOTYPE  GLOBAL DEFAULT    8 __[...]@@LINUX_2.6.15
           9: 0000000000000454    12 NOTYPE  GLOBAL DEFAULT    8 __[...]@@LINUX_2.6.15
          10: 00000000000004d0    84 NOTYPE  GLOBAL DEFAULT    8 __[...]@@LINUX_2.6.15
          11: 00000000000005bc    52 NOTYPE  GLOBAL DEFAULT    8 __[...]@@LINUX_2.6.15
      
      Symbol table '.symtab' contains 56 entries:
         Num:    Value          Size Type    Bind   Vis      Ndx Name
      ...
          45: 0000000000000000     0 OBJECT  GLOBAL DEFAULT  ABS LINUX_2.6.15
          46: 00000000000006c0    48 NOTYPE  GLOBAL DEFAULT    8 __kernel_getcpu
          47: 0000000000000524    84 NOTYPE  GLOBAL DEFAULT    8 __kernel_clock_getres
          48: 00000000000005f0    36 NOTYPE  GLOBAL DEFAULT    8 __kernel_get_tbfreq
          49: 000000000000047c    84 NOTYPE  GLOBAL DEFAULT    8 __kernel_gettimeofday
          50: 0000000000000614   172 NOTYPE  GLOBAL DEFAULT    8 __kernel_sync_dicache
          51: 00000000000006f0    84 NOTYPE  GLOBAL DEFAULT    8 __kernel_getrandom
          52: 0000000000000454    12 NOTYPE  GLOBAL DEFAULT    8 __kernel_sigtram[...]
          53: 0000000000000578    68 NOTYPE  GLOBAL DEFAULT    8 __kernel_time
          54: 00000000000004d0    84 NOTYPE  GLOBAL DEFAULT    8 __kernel_clock_g[...]
          55: 00000000000005bc    52 NOTYPE  GLOBAL DEFAULT    8 __kernel_get_sys[...]
      
      Fixes: 98eedc3a ("Document the vDSO and add a reference parser")
      Signed-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
      Acked-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      ba83b323
    • Christophe Leroy's avatar
      selftests: vDSO: fix vdso_config for powerpc · 7d297c41
      Christophe Leroy authored
      Running vdso_test_correctness on powerpc64 gives the following warning:
      
        ~ # ./vdso_test_correctness
        Warning: failed to find clock_gettime64 in vDSO
      
      This is because vdso_test_correctness was built with VDSO_32BIT defined.
      
      __powerpc__ macro is defined on both powerpc32 and powerpc64 so
      __powerpc64__ needs to be checked first in vdso_config.h
      
      Fixes: 693f5ca0 ("kselftest: Extend vDSO selftest")
      Signed-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
      Acked-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      7d297c41
    • Christophe Leroy's avatar
      selftests: vDSO: fix vDSO name for powerpc · 59eb856c
      Christophe Leroy authored
      Following error occurs when running vdso_test_correctness on powerpc:
      
      ~ # ./vdso_test_correctness
      [WARN]	failed to find vDSO
      [SKIP]	No vDSO, so skipping clock_gettime() tests
      [SKIP]	No vDSO, so skipping clock_gettime64() tests
      [RUN]	Testing getcpu...
      [OK]	CPU 0: syscall: cpu 0, node 0
      
      On powerpc, vDSO is neither called linux-vdso.so.1 nor linux-gate.so.1
      but linux-vdso32.so.1 or linux-vdso64.so.1.
      
      Also search those two names before giving up.
      
      Fixes: c7e5789b ("kselftest: Move test_vdso to the vDSO test suite")
      Signed-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
      Acked-by: default avatarShuah Khan <skhan@linuxfoundation.org>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      59eb856c
    • Jason A. Donenfeld's avatar
      selftests: vDSO: skip getrandom test if architecture is unsupported · f78280b1
      Jason A. Donenfeld authored
      If the getrandom test compiles for an arch, don't exit fatally if the
      actual cpu it's running on is unsupported.
      Suggested-by: default avatarAdhemerval Zanella Netto <adhemerval.zanella@linaro.org>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      f78280b1
    • Xi Ruoyao's avatar
      selftests: vDSO: use KHDR_INCLUDES for UAPI headers for getrandom test · b90eeff1
      Xi Ruoyao authored
      Building test_vdso_getrandom currently leads to following issue:
      
          In file included from /home/xry111/git-repos/linux/tools/include/linux/compiler_types.h:36,
                           from /home/xry111/git-repos/linux/include/uapi/linux/stddef.h:5,
                           from /home/xry111/git-repos/linux/include/uapi/linux/posix_types.h:5,
                           from /usr/include/asm/sigcontext.h:12,
                           from /usr/include/bits/sigcontext.h:30,
                           from /usr/include/signal.h:301,
                           from vdso_test_getrandom.c:14:
          /home/xry111/git-repos/linux/tools/include/linux/compiler-gcc.h:3:2: error: #error "Please don't include <linux/compiler-gcc.h> directly, include <linux/compiler.h> instead."
              3 | #error "Please don't include <linux/compiler-gcc.h> directly, include <linux/compiler.h> instead."
                |  ^~~~~
      
      It's because the compiler_types.h inclusion in
      include/uapi/linux/stddef.h is expected to be removed by the
      header_install.sh script, as compiler_types.h shouldn't be used from
      user space.
      
      Add KHDR_INCLUDES before the existing include/uapi inclusion so that
      usr/include takes precedence if it's populated.
      Signed-off-by: default avatarXi Ruoyao <xry111@xry111.site>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      b90eeff1
    • Jason A. Donenfeld's avatar
      selftests: vDSO: remove unnecessary command line defs from chacha test · be915515
      Jason A. Donenfeld authored
      CONFIG_FUNCTION_ALIGNMENT=0 is no longer necessary and BULID_VDSO wasn't
      spelled right while BUILD_VDSO isn't necessary, so just remove these.
      Reported-by: default avatarAdhemerval Zanella Netto <adhemerval.zanella@linaro.org>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      be915515
    • Jason A. Donenfeld's avatar
      selftests: vDSO: separate LDLIBS from CFLAGS for libsodium · a5330eb3
      Jason A. Donenfeld authored
      On systems that set -Wl,--as-needed, putting the -lsodium in the wrong
      place on the command line means we get a linker error:
      
            CC       vdso_test_chacha
          /usr/bin/ld: /tmp/ccKpjnSM.o: in function `main':
          vdso_test_chacha.c:(.text+0x276): undefined reference to `crypto_stream_chacha20'
          collect2: error: ld returned 1 exit status
      
      Fix this by passing pkg-config's --libs output to the LDFLAGS field
      instead of the CFLAGS field, as is customary.
      Reported-by: default avatarAdhemerval Zanella Netto <adhemerval.zanella@linaro.org>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      a5330eb3
    • Xi Ruoyao's avatar
      selftests: vDSO: add --cflags for pkg-config command querying libsodium · 1e661b34
      Xi Ruoyao authored
      When libsodium is installed into its own prefix, the --cflags output is
      needed for the compiler to find libsodium headers.
      Signed-off-by: default avatarXi Ruoyao <xry111@xry111.site>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      1e661b34
    • Christophe Leroy's avatar
      selftests: vDSO: look for arch-specific function name in getrandom test · e1bbcab4
      Christophe Leroy authored
      Don't hard-code x86 specific names. Rather, use vdso_config definitions
      to find the correct function matching the architecture.
      
      Add random VDSO function names in names[][]. Remove the #ifdef
      CONFIG_VDSO32, as having the name there all the time is harmless and
      guaranties a steady index for following strings.
      Signed-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
      [Jason: add [6] to variable declaration rather than each usage site.]
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      e1bbcab4
    • Christophe Leroy's avatar
      selftests: vDSO: fix include order in build of test_vdso_chacha · f8d92fc5
      Christophe Leroy authored
      Building test_vdso_chacha currently leads to following issue:
      
        In file included from /home/chleroy/linux-powerpc/include/linux/limits.h:7,
                         from /opt/powerpc64-e5500--glibc--stable-2024.02-1/powerpc64-buildroot-linux-gnu/sysroot/usr/include/bits/local_lim.h:38,
                         from /opt/powerpc64-e5500--glibc--stable-2024.02-1/powerpc64-buildroot-linux-gnu/sysroot/usr/include/bits/posix1_lim.h:161,
                         from /opt/powerpc64-e5500--glibc--stable-2024.02-1/powerpc64-buildroot-linux-gnu/sysroot/usr/include/limits.h:195,
                         from /opt/powerpc64-e5500--glibc--stable-2024.02-1/lib/gcc/powerpc64-buildroot-linux-gnu/12.3.0/include-fixed/limits.h:203,
                         from /opt/powerpc64-e5500--glibc--stable-2024.02-1/lib/gcc/powerpc64-buildroot-linux-gnu/12.3.0/include-fixed/syslimits.h:7,
                         from /opt/powerpc64-e5500--glibc--stable-2024.02-1/lib/gcc/powerpc64-buildroot-linux-gnu/12.3.0/include-fixed/limits.h:34,
                         from /tmp/sodium/usr/local/include/sodium/export.h:7,
                         from /tmp/sodium/usr/local/include/sodium/crypto_stream_chacha20.h:14,
                         from vdso_test_chacha.c:6:
        /opt/powerpc64-e5500--glibc--stable-2024.02-1/powerpc64-buildroot-linux-gnu/sysroot/usr/include/bits/xopen_lim.h:99:6: error: missing binary operator before token "("
           99 | # if INT_MAX == 32767
              |      ^~~~~~~
        /opt/powerpc64-e5500--glibc--stable-2024.02-1/powerpc64-buildroot-linux-gnu/sysroot/usr/include/bits/xopen_lim.h:102:7: error: missing binary operator before token "("
          102 | #  if INT_MAX == 2147483647
              |       ^~~~~~~
        /opt/powerpc64-e5500--glibc--stable-2024.02-1/powerpc64-buildroot-linux-gnu/sysroot/usr/include/bits/xopen_lim.h:126:6: error: missing binary operator before token "("
          126 | # if LONG_MAX == 2147483647
              |      ^~~~~~~~
      
      This is due to kernel include/linux/limits.h being included instead of
      libc's limits.h.
      
      This is because directory include/ is added through option -isystem so
      it goes prior to glibc's include directory.
      
      Replace -isystem by -idirafter.
      
      But this implies that now tools/include/linux/linkage.h is included
      instead of include/linux/linkage.h, so define a stub for
      SYM_FUNC_START() and SYM_FUNC_END().
      Signed-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      f8d92fc5
    • Christophe Leroy's avatar
      selftests: vDSO: don't hard-code location of vDSO sources · 20a9af05
      Christophe Leroy authored
      Architectures use different location for vDSO sources:
      
      	arch/mips/vdso
      	arch/sparc/vdso
      	arch/arm64/kernel/vdso
      	arch/riscv/kernel/vdso
      	arch/csky/kernel/vdso
      	arch/x86/um/vdso
      	arch/x86/entry/vdso
      	arch/powerpc/kernel/vdso
      	arch/arm/vdso
      	arch/loongarch/vdso
      
      Don't hard-code vdso sources location in selftest Makefile. Instead
      create a vdso/ symbolic link in tools/arch/$arch/ and update Makefile
      accordingly.
      Signed-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      20a9af05
    • Jason A. Donenfeld's avatar
      selftests: vDSO: simplify getrandom thread local storage and structs · 01b52f01
      Jason A. Donenfeld authored
      Rather than using pthread_get/set_specific, just use gcc's __thread
      annotation, which is noticeably faster and makes the code more obvious.
      
      Also, just have one simplified struct called vgrnd, instead of trying to
      split things up semantically. Those divisions were useful when this code
      was split across several commit *messages*, but doesn't make as much
      sense within a single file. This should make the code more clear and
      provide a better example for implementers.
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      01b52f01
  3. 29 Aug, 2024 1 commit
    • Linus Torvalds's avatar
      Merge tag 'random-6.11-rc6-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/crng/random · d5d547aa
      Linus Torvalds authored
      Pull random number generator fix from Jason Donenfeld:
       "Reject invalid flags passed to vgetrandom() in the same way that
        getrandom() does, so that the behavior is the same, from Yann.
      
        The flags argument to getrandom() only has a behavioral effect on the
        function if the RNG isn't initialized yet, so vgetrandom() falls back
        to the syscall in that case. But if the RNG is initialized, all of the
        flags behave the same way, so vgetrandom() didn't bother checking
        them, and just ignored them entirely.
      
        But that doesn't account for invalid flags passed in, which need to be
        rejected so we can use them later"
      
      * tag 'random-6.11-rc6-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/crng/random:
        random: vDSO: reject unknown getrandom() flags
      d5d547aa
  4. 28 Aug, 2024 6 commits
  5. 27 Aug, 2024 2 commits