mbox series

[v4,0/4] LoongArch: Implement getrandom() in vDSO

Message ID 20240827132018.88854-1-xry111@xry111.site (mailing list archive)
Headers show
Series LoongArch: Implement getrandom() in vDSO | expand

Message

Xi Ruoyao Aug. 27, 2024, 1:20 p.m. UTC
For the rationale to implement getrandom() in vDSO see [1].

The vDSO getrandom() needs a stack-less ChaCha20 implementation, so we
need to add architecture-specific code and wire it up with the generic
code.

The implementation is tested with the kernel vDSO selftests, which need
to be adapted as well.  The selftest changes are also included in the
series.

The vdso_test_getrandom bench-single result:

       vdso: 25000000 times in 0.501461533 seconds
       libc: 25000000 times in 6.975149458 seconds
    syscall: 25000000 times in 6.985865529 seconds

The vdso_test_getrandom bench-multi result:

       vdso: 25000000 x 256 times in 28.688809414 seconds
       libc: 25000000 x 256 times in 356.863400242 seconds
       syscall: 25000000 x 256 times in 338.562183570 seconds

[1]:https://lore.kernel.org/all/20240712014009.281406-1-Jason@zx2c4.com/

Cc: linux-crypto@vger.kernel.org
Cc: loongarch@lists.linux.dev
Cc: Jinyang He <hejinyang@loongson.cn>
Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
Cc: Arnd Bergmann <arnd@arndb.de>

[v3]->v4:
- Remove LSX implementation, which isn't much faster than the generic
  implementaion.
- Rebase onto crng/random.git:
  - Define __arch_get_k_vdso_rng_data instead of using inline asm to
    provide the _vdso_rng_data symbol in a magic way.
  - Remove memset.S.
  - Use c-getrandom-y to easily include the generic C code.
  - The benchmark results seem better than v3, maybe related to the TLS
    refactoring in random.git.
- Add patches for selftests.

[v2]->v3:
- Add a generic LoongArch implementation for which LSX isn't needed.

v1->v2:
- Properly send the series to the list.

[v3]:https://lore.kernel.org/all/20240816110717.10249-1-xry111@xry111.site/
[v2]:https://lore.kernel.org/all/20240815133357.35829-1-xry111@xry111.site/

Xi Ruoyao (4):
  LoongArch: vDSO: Wire up getrandom() vDSO implementation
  selftests/vDSO: Add --cflags for pkg-config command querying libsodium
  selftests/vDSO: Use KHDR_INCLUDES to locate UAPI headers for
    vdso_test_getrandom
  selftests/vDSO: Enable vdso getrandom tests for LoongArch

 arch/loongarch/Kconfig                      |   1 +
 arch/loongarch/include/asm/vdso/getrandom.h |  47 ++++
 arch/loongarch/include/asm/vdso/vdso.h      |   8 +
 arch/loongarch/include/asm/vdso/vsyscall.h  |  10 +
 arch/loongarch/kernel/asm-offsets.c         |  10 +
 arch/loongarch/kernel/vdso.c                |   2 +
 arch/loongarch/vdso/Makefile                |   6 +
 arch/loongarch/vdso/vdso.lds.S              |   1 +
 arch/loongarch/vdso/vgetrandom-chacha.S     | 239 ++++++++++++++++++++
 arch/loongarch/vdso/vgetrandom.c            |  12 +
 tools/arch/loongarch/vdso                   |   1 +
 tools/testing/selftests/vDSO/Makefile       |   8 +-
 12 files changed, 341 insertions(+), 4 deletions(-)
 create mode 100644 arch/loongarch/include/asm/vdso/getrandom.h
 create mode 100644 arch/loongarch/vdso/vgetrandom-chacha.S
 create mode 100644 arch/loongarch/vdso/vgetrandom.c
 create mode 120000 tools/arch/loongarch/vdso


base-commit: c64dcc01ebf2b7d5a7cb56b5c6a4b6adc2273774

Comments

Jason A. Donenfeld Aug. 27, 2024, 1:51 p.m. UTC | #1
On Tue, Aug 27, 2024 at 09:20:13PM +0800, Xi Ruoyao wrote:
> Cc: linux-crypto@vger.kernel.org
> Cc: loongarch@lists.linux.dev
> Cc: Jinyang He <hejinyang@loongson.cn>
> Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
> Cc: Arnd Bergmann <arnd@arndb.de>

BTW, you might also want to CC future versions of this to
tglx@linutronix.de.