* [PATCH v4 0/4] LoongArch: Implement getrandom() in vDSO
@ 2024-08-27 13:20 Xi Ruoyao
2024-08-27 13:20 ` [PATCH v4 1/4] LoongArch: vDSO: Wire up getrandom() vDSO implementation Xi Ruoyao
` (4 more replies)
0 siblings, 5 replies; 29+ messages in thread
From: Xi Ruoyao @ 2024-08-27 13:20 UTC (permalink / raw)
To: Jason A . Donenfeld, Huacai Chen, WANG Xuerui
Cc: Xi Ruoyao, linux-crypto, loongarch, Jinyang He, Tiezhu Yang,
Arnd Bergmann
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
--
2.46.0
^ permalink raw reply [flat|nested] 29+ messages in thread
* [PATCH v4 1/4] LoongArch: vDSO: Wire up getrandom() vDSO implementation
2024-08-27 13:20 [PATCH v4 0/4] LoongArch: Implement getrandom() in vDSO Xi Ruoyao
@ 2024-08-27 13:20 ` Xi Ruoyao
2024-08-27 13:36 ` Xi Ruoyao
` (4 more replies)
2024-08-27 13:20 ` [PATCH v4 2/4] selftests/vDSO: Add --cflags for pkg-config command querying libsodium Xi Ruoyao
` (3 subsequent siblings)
4 siblings, 5 replies; 29+ messages in thread
From: Xi Ruoyao @ 2024-08-27 13:20 UTC (permalink / raw)
To: Jason A . Donenfeld, Huacai Chen, WANG Xuerui
Cc: Xi Ruoyao, linux-crypto, loongarch, Jinyang He, Tiezhu Yang,
Arnd Bergmann
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.
Signed-off-by: Xi Ruoyao <xry111@xry111.site>
---
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 +
10 files changed, 336 insertions(+)
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
diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig
index 70f169210b52..14821c2aba5b 100644
--- a/arch/loongarch/Kconfig
+++ b/arch/loongarch/Kconfig
@@ -190,6 +190,7 @@ config LOONGARCH
select TRACE_IRQFLAGS_SUPPORT
select USE_PERCPU_NUMA_NODE_ID
select USER_STACKTRACE_SUPPORT
+ select VDSO_GETRANDOM
select ZONE_DMA32
config 32BIT
diff --git a/arch/loongarch/include/asm/vdso/getrandom.h b/arch/loongarch/include/asm/vdso/getrandom.h
new file mode 100644
index 000000000000..a369588a4ebf
--- /dev/null
+++ b/arch/loongarch/include/asm/vdso/getrandom.h
@@ -0,0 +1,47 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2024 Xi Ruoyao <xry111@xry111.site>. All Rights Reserved.
+ */
+#ifndef __ASM_VDSO_GETRANDOM_H
+#define __ASM_VDSO_GETRANDOM_H
+
+#ifndef __ASSEMBLY__
+
+#include <asm/unistd.h>
+#include <asm/vdso/vdso.h>
+
+static __always_inline ssize_t getrandom_syscall(void *_buffer,
+ size_t _len,
+ unsigned int _flags)
+{
+ register long ret asm("a0");
+ register long int nr asm("a7") = __NR_getrandom;
+ register void *buffer asm("a0") = _buffer;
+ register size_t len asm("a1") = _len;
+ register unsigned int flags asm("a2") = _flags;
+
+ asm volatile(
+ " syscall 0\n"
+ : "+r" (ret)
+ : "r" (nr), "r" (buffer), "r" (len), "r" (flags)
+ : "$t0", "$t1", "$t2", "$t3", "$t4", "$t5", "$t6", "$t7", "$t8",
+ "memory");
+
+ return ret;
+}
+
+static __always_inline const struct vdso_rng_data *__arch_get_vdso_rng_data(
+ void)
+{
+ return (const struct vdso_rng_data *)(
+ get_vdso_data() +
+ VVAR_LOONGARCH_PAGES_START * PAGE_SIZE +
+ offsetof(struct loongarch_vdso_data, rng_data));
+}
+
+extern void __arch_chacha20_blocks_nostack(u8 *dst_bytes, const u32 *key,
+ u32 *counter, size_t nblocks);
+
+#endif /* !__ASSEMBLY__ */
+
+#endif /* __ASM_VDSO_GETRANDOM_H */
diff --git a/arch/loongarch/include/asm/vdso/vdso.h b/arch/loongarch/include/asm/vdso/vdso.h
index 5a12309d9fb5..a2e24c3007e2 100644
--- a/arch/loongarch/include/asm/vdso/vdso.h
+++ b/arch/loongarch/include/asm/vdso/vdso.h
@@ -4,6 +4,9 @@
* Copyright (C) 2020-2022 Loongson Technology Corporation Limited
*/
+#ifndef _ASM_VDSO_VDSO_H
+#define _ASM_VDSO_VDSO_H
+
#ifndef __ASSEMBLY__
#include <asm/asm.h>
@@ -16,6 +19,9 @@ struct vdso_pcpu_data {
struct loongarch_vdso_data {
struct vdso_pcpu_data pdata[NR_CPUS];
+#ifdef CONFIG_VDSO_GETRANDOM
+ struct vdso_rng_data rng_data;
+#endif
};
/*
@@ -63,3 +69,5 @@ static inline unsigned long get_vdso_data(void)
}
#endif /* __ASSEMBLY__ */
+
+#endif
diff --git a/arch/loongarch/include/asm/vdso/vsyscall.h b/arch/loongarch/include/asm/vdso/vsyscall.h
index 5de615383a22..dbc0c8aaec59 100644
--- a/arch/loongarch/include/asm/vdso/vsyscall.h
+++ b/arch/loongarch/include/asm/vdso/vsyscall.h
@@ -8,6 +8,7 @@
#include <vdso/datapage.h>
extern struct vdso_data *vdso_data;
+extern struct vdso_rng_data *vdso_rng_data;
/*
* Update the vDSO data page to keep in sync with kernel timekeeping.
@@ -19,6 +20,15 @@ struct vdso_data *__loongarch_get_k_vdso_data(void)
}
#define __arch_get_k_vdso_data __loongarch_get_k_vdso_data
+#ifdef CONFIG_VDSO_GETRANDOM
+static __always_inline
+struct vdso_rng_data *__loongarch_get_k_vdso_rng_data(void)
+{
+ return vdso_rng_data;
+}
+#define __arch_get_k_vdso_rng_data __loongarch_get_k_vdso_rng_data
+#endif
+
/* The asm-generic header needs to be included after the definitions above */
#include <asm-generic/vdso/vsyscall.h>
diff --git a/arch/loongarch/kernel/asm-offsets.c b/arch/loongarch/kernel/asm-offsets.c
index bee9f7a3108f..86f6d8a6dc23 100644
--- a/arch/loongarch/kernel/asm-offsets.c
+++ b/arch/loongarch/kernel/asm-offsets.c
@@ -14,6 +14,7 @@
#include <asm/ptrace.h>
#include <asm/processor.h>
#include <asm/ftrace.h>
+#include <asm/vdso/vdso.h>
static void __used output_ptreg_defines(void)
{
@@ -321,3 +322,12 @@ static void __used output_kvm_defines(void)
OFFSET(KVM_GPGD, kvm, arch.pgd);
BLANK();
}
+
+#ifdef CONFIG_VDSO_GETRANDOM
+static void __used output_vdso_rng_defines(void)
+{
+ COMMENT("LoongArch VDSO getrandom offsets.");
+ OFFSET(VDSO_RNG_DATA, loongarch_vdso_data, rng_data);
+ BLANK();
+}
+#endif
diff --git a/arch/loongarch/kernel/vdso.c b/arch/loongarch/kernel/vdso.c
index 90dfccb41c14..2af05ba5f121 100644
--- a/arch/loongarch/kernel/vdso.c
+++ b/arch/loongarch/kernel/vdso.c
@@ -22,6 +22,7 @@
#include <vdso/helpers.h>
#include <vdso/vsyscall.h>
#include <vdso/datapage.h>
+#include <generated/asm-offsets.h>
#include <generated/vdso-offsets.h>
extern char vdso_start[], vdso_end[];
@@ -37,6 +38,7 @@ static union {
static struct page *vdso_pages[] = { NULL };
struct vdso_data *vdso_data = generic_vdso_data.data;
struct vdso_pcpu_data *vdso_pdata = loongarch_vdso_data.vdata.pdata;
+struct vdso_rng_data *vdso_rng_data = &loongarch_vdso_data.vdata.rng_data;
static int vdso_mremap(const struct vm_special_mapping *sm, struct vm_area_struct *new_vma)
{
diff --git a/arch/loongarch/vdso/Makefile b/arch/loongarch/vdso/Makefile
index d724d46b07c8..252ed56aa489 100644
--- a/arch/loongarch/vdso/Makefile
+++ b/arch/loongarch/vdso/Makefile
@@ -6,6 +6,8 @@ include $(srctree)/lib/vdso/Makefile
obj-vdso-y := elf.o vgetcpu.o vgettimeofday.o sigreturn.o
+obj-vdso-$(CONFIG_VDSO_GETRANDOM) += vgetrandom.o vgetrandom-chacha.o
+
# Common compiler flags between ABIs.
ccflags-vdso := \
$(filter -I%,$(KBUILD_CFLAGS)) \
@@ -29,6 +31,10 @@ ifneq ($(c-gettimeofday-y),)
CFLAGS_vgettimeofday.o += -include $(c-gettimeofday-y)
endif
+ifneq ($(c-getrandom-y),)
+ CFLAGS_vgetrandom.o += -include $(c-getrandom-y)
+endif
+
# VDSO linker flags.
ldflags-y := -Bsymbolic --no-undefined -soname=linux-vdso.so.1 \
$(filter -E%,$(KBUILD_CFLAGS)) -nostdlib -shared \
diff --git a/arch/loongarch/vdso/vdso.lds.S b/arch/loongarch/vdso/vdso.lds.S
index 56ad855896de..2c965a597d9e 100644
--- a/arch/loongarch/vdso/vdso.lds.S
+++ b/arch/loongarch/vdso/vdso.lds.S
@@ -63,6 +63,7 @@ VERSION
__vdso_clock_gettime;
__vdso_gettimeofday;
__vdso_rt_sigreturn;
+ __vdso_getrandom;
local: *;
};
}
diff --git a/arch/loongarch/vdso/vgetrandom-chacha.S b/arch/loongarch/vdso/vgetrandom-chacha.S
new file mode 100644
index 000000000000..2e42198f2faf
--- /dev/null
+++ b/arch/loongarch/vdso/vgetrandom-chacha.S
@@ -0,0 +1,239 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2024 Xi Ruoyao <xry111@xry111.site>. All Rights Reserved.
+ */
+
+#include <asm/asm.h>
+#include <asm/regdef.h>
+#include <linux/linkage.h>
+
+.text
+
+/* Salsa20 quarter-round */
+.macro QR a b c d
+ add.w \a, \a, \b
+ xor \d, \d, \a
+ rotri.w \d, \d, 16
+
+ add.w \c, \c, \d
+ xor \b, \b, \c
+ rotri.w \b, \b, 20
+
+ add.w \a, \a, \b
+ xor \d, \d, \a
+ rotri.w \d, \d, 24
+
+ add.w \c, \c, \d
+ xor \b, \b, \c
+ rotri.w \b, \b, 25
+.endm
+
+/*
+ * Very basic LoongArch implementation of ChaCha20. Produces a given positive
+ * number of blocks of output with a nonce of 0, taking an input key and
+ * 8-byte counter. Importantly does not spill to the stack. Its arguments
+ * are:
+ *
+ * a0: output bytes
+ * a1: 32-byte key input
+ * a2: 8-byte counter input/output
+ * a3: number of 64-byte blocks to write to output
+ */
+SYM_FUNC_START(__arch_chacha20_blocks_nostack)
+
+/* We don't need a frame pointer */
+#define s9 fp
+
+#define output a0
+#define key a1
+#define counter a2
+#define nblocks a3
+#define i a4
+#define state0 s0
+#define state1 s1
+#define state2 s2
+#define state3 s3
+#define state4 s4
+#define state5 s5
+#define state6 s6
+#define state7 s7
+#define state8 s8
+#define state9 s9
+#define state10 a5
+#define state11 a6
+#define state12 a7
+#define state13 t0
+#define state14 t1
+#define state15 t2
+#define cnt_lo t3
+#define cnt_hi t4
+#define copy0 t5
+#define copy1 t6
+#define copy2 t7
+
+/* Reuse i as copy3 */
+#define copy3 i
+
+ /*
+ * The ABI requires s0-s9 saved, and sp aligned to 16-byte.
+ * This does not violate the stack-less requirement: no sensitive data
+ * is spilled onto the stack.
+ */
+ PTR_ADDI sp, sp, (-SZREG * 10) & STACK_ALIGN
+ REG_S s0, sp, 0
+ REG_S s1, sp, SZREG
+ REG_S s2, sp, SZREG * 2
+ REG_S s3, sp, SZREG * 3
+ REG_S s4, sp, SZREG * 4
+ REG_S s5, sp, SZREG * 5
+ REG_S s6, sp, SZREG * 6
+ REG_S s7, sp, SZREG * 7
+ REG_S s8, sp, SZREG * 8
+ REG_S s9, sp, SZREG * 9
+
+ li.w copy0, 0x61707865
+ li.w copy1, 0x3320646e
+ li.w copy2, 0x79622d32
+
+ ld.w cnt_lo, counter, 0
+ ld.w cnt_hi, counter, 4
+
+.Lblock:
+ /* state[0,1,2,3] = "expand 32-byte k" */
+ move state0, copy0
+ move state1, copy1
+ move state2, copy2
+ li.w state3, 0x6b206574
+
+ /* state[4,5,..,11] = key */
+ ld.w state4, key, 0
+ ld.w state5, key, 4
+ ld.w state6, key, 8
+ ld.w state7, key, 12
+ ld.w state8, key, 16
+ ld.w state9, key, 20
+ ld.w state10, key, 24
+ ld.w state11, key, 28
+
+ /* state[12,13] = counter */
+ move state12, cnt_lo
+ move state13, cnt_hi
+
+ /* state[14,15] = 0 */
+ move state14, zero
+ move state15, zero
+
+ li.w i, 10
+.Lpermute:
+ /* odd round */
+ QR state0, state4, state8, state12
+ QR state1, state5, state9, state13
+ QR state2, state6, state10, state14
+ QR state3, state7, state11, state15
+
+ /* even round */
+ QR state0, state5, state10, state15
+ QR state1, state6, state11, state12
+ QR state2, state7, state8, state13
+ QR state3, state4, state9, state14
+
+ addi.w i, i, -1
+ bnez i, .Lpermute
+
+ /* copy[3] = "expa" */
+ li.w copy3, 0x6b206574
+
+ /* output[0,1,2,3] = copy[0,1,2,3] + state[0,1,2,3] */
+ add.w state0, state0, copy0
+ add.w state1, state1, copy1
+ add.w state2, state2, copy2
+ add.w state3, state3, copy3
+ st.w state0, output, 0
+ st.w state1, output, 4
+ st.w state2, output, 8
+ st.w state3, output, 12
+
+ /* from now on state[0,1,2,3] are scratch registers */
+
+ /* state[0,1,2,3] = lo32(key) */
+ ld.w state0, key, 0
+ ld.w state1, key, 4
+ ld.w state2, key, 8
+ ld.w state3, key, 12
+
+ /* output[4,5,6,7] = state[0,1,2,3] + state[4,5,6,7] */
+ add.w state4, state4, state0
+ add.w state5, state5, state1
+ add.w state6, state6, state2
+ add.w state7, state7, state3
+ st.w state4, output, 16
+ st.w state5, output, 20
+ st.w state6, output, 24
+ st.w state7, output, 28
+
+ /* state[0,1,2,3] = hi32(key) */
+ ld.w state0, key, 16
+ ld.w state1, key, 20
+ ld.w state2, key, 24
+ ld.w state3, key, 28
+
+ /* output[8,9,10,11] = state[0,1,2,3] + state[8,9,10,11] */
+ add.w state8, state8, state0
+ add.w state9, state9, state1
+ add.w state10, state10, state2
+ add.w state11, state11, state3
+ st.w state8, output, 32
+ st.w state9, output, 36
+ st.w state10, output, 40
+ st.w state11, output, 44
+
+ /* output[12,13,14,15] = state[12,13,14,15] + [cnt_lo, cnt_hi, 0, 0] */
+ add.w state12, state12, cnt_lo
+ add.w state13, state13, cnt_hi
+ st.w state12, output, 48
+ st.w state13, output, 52
+ st.w state14, output, 56
+ st.w state15, output, 60
+
+ /* ++counter */
+ addi.w cnt_lo, cnt_lo, 1
+ sltui state0, cnt_lo, 1
+ add.w cnt_hi, cnt_hi, state0
+
+ /* output += 64 */
+ PTR_ADDI output, output, 64
+ /* --nblocks */
+ PTR_ADDI nblocks, nblocks, -1
+ bnez nblocks, .Lblock
+
+ /* counter = [cnt_lo, cnt_hi] */
+ st.w cnt_lo, counter, 0
+ st.w cnt_hi, counter, 4
+
+ /*
+ * Zero out the potentially sensitive regs, in case nothing uses these
+ * again. As at now copy[0,1,2,3] just contains "expand 32-byte k" and
+ * state[0,...,9] are s0-s9 those we'll restore in the epilogue, so we
+ * only need to zero state[11,...,15].
+ */
+ move state10, zero
+ move state11, zero
+ move state12, zero
+ move state13, zero
+ move state14, zero
+ move state15, zero
+
+ REG_L s0, sp, 0
+ REG_L s1, sp, SZREG
+ REG_L s2, sp, SZREG * 2
+ REG_L s3, sp, SZREG * 3
+ REG_L s4, sp, SZREG * 4
+ REG_L s5, sp, SZREG * 5
+ REG_L s6, sp, SZREG * 6
+ REG_L s7, sp, SZREG * 7
+ REG_L s8, sp, SZREG * 8
+ REG_L s9, sp, SZREG * 9
+ PTR_ADDI sp, sp, -((-SZREG * 10) & STACK_ALIGN)
+
+ jr ra
+SYM_FUNC_END(__arch_chacha20_blocks_nostack)
diff --git a/arch/loongarch/vdso/vgetrandom.c b/arch/loongarch/vdso/vgetrandom.c
new file mode 100644
index 000000000000..b9142a5b5d77
--- /dev/null
+++ b/arch/loongarch/vdso/vgetrandom.c
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2024 Xi Ruoyao <xry111@xry111.site>. All Rights Reserved.
+ */
+#include <linux/types.h>
+
+ssize_t __vdso_getrandom(void *buffer, size_t len, unsigned int flags,
+ void *opaque_state, size_t opaque_len)
+{
+ return __cvdso_getrandom(buffer, len, flags, opaque_state,
+ opaque_len);
+}
--
2.46.0
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH v4 2/4] selftests/vDSO: Add --cflags for pkg-config command querying libsodium
2024-08-27 13:20 [PATCH v4 0/4] LoongArch: Implement getrandom() in vDSO Xi Ruoyao
2024-08-27 13:20 ` [PATCH v4 1/4] LoongArch: vDSO: Wire up getrandom() vDSO implementation Xi Ruoyao
@ 2024-08-27 13:20 ` Xi Ruoyao
2024-08-27 13:54 ` Jason A. Donenfeld
2024-08-27 13:20 ` [PATCH v4 3/4] selftests/vDSO: Use KHDR_INCLUDES to locate UAPI headers for vdso_test_getrandom Xi Ruoyao
` (2 subsequent siblings)
4 siblings, 1 reply; 29+ messages in thread
From: Xi Ruoyao @ 2024-08-27 13:20 UTC (permalink / raw)
To: Jason A . Donenfeld, Huacai Chen, WANG Xuerui
Cc: Xi Ruoyao, linux-crypto, loongarch, Jinyang He, Tiezhu Yang,
Arnd Bergmann
When libsodium is installed into its own prefix, the --cflags output is
needed for the compiler to find libsodium headers.
Signed-off-by: Xi Ruoyao <xry111@xry111.site>
---
tools/testing/selftests/vDSO/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/vDSO/Makefile b/tools/testing/selftests/vDSO/Makefile
index 10ffdda3f2fa..180854eb9fec 100644
--- a/tools/testing/selftests/vDSO/Makefile
+++ b/tools/testing/selftests/vDSO/Makefile
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
uname_M := $(shell uname -m 2>/dev/null || echo not)
ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/)
-SODIUM := $(shell pkg-config --libs libsodium 2>/dev/null)
+SODIUM := $(shell pkg-config --libs --cflags libsodium 2>/dev/null)
TEST_GEN_PROGS := vdso_test_gettimeofday
TEST_GEN_PROGS += vdso_test_getcpu
--
2.46.0
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH v4 3/4] selftests/vDSO: Use KHDR_INCLUDES to locate UAPI headers for vdso_test_getrandom
2024-08-27 13:20 [PATCH v4 0/4] LoongArch: Implement getrandom() in vDSO Xi Ruoyao
2024-08-27 13:20 ` [PATCH v4 1/4] LoongArch: vDSO: Wire up getrandom() vDSO implementation Xi Ruoyao
2024-08-27 13:20 ` [PATCH v4 2/4] selftests/vDSO: Add --cflags for pkg-config command querying libsodium Xi Ruoyao
@ 2024-08-27 13:20 ` Xi Ruoyao
2024-08-27 13:58 ` Jason A. Donenfeld
2024-08-27 13:20 ` [PATCH v4 4/4] selftests/vDSO: Enable vdso getrandom tests for LoongArch Xi Ruoyao
2024-08-27 13:51 ` [PATCH v4 0/4] LoongArch: Implement getrandom() in vDSO Jason A. Donenfeld
4 siblings, 1 reply; 29+ messages in thread
From: Xi Ruoyao @ 2024-08-27 13:20 UTC (permalink / raw)
To: Jason A . Donenfeld, Huacai Chen, WANG Xuerui
Cc: Xi Ruoyao, linux-crypto, loongarch, Jinyang He, Tiezhu Yang,
Arnd Bergmann
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 the
user space.
Signed-off-by: Xi Ruoyao <xry111@xry111.site>
---
tools/testing/selftests/vDSO/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/vDSO/Makefile b/tools/testing/selftests/vDSO/Makefile
index 180854eb9fec..e346890d4c91 100644
--- a/tools/testing/selftests/vDSO/Makefile
+++ b/tools/testing/selftests/vDSO/Makefile
@@ -38,7 +38,7 @@ $(OUTPUT)/vdso_test_correctness: LDFLAGS += -ldl
$(OUTPUT)/vdso_test_getrandom: parse_vdso.c
$(OUTPUT)/vdso_test_getrandom: CFLAGS += -isystem $(top_srcdir)/tools/include \
- -isystem $(top_srcdir)/include/uapi
+ $(KHDR_INCLUDES)
$(OUTPUT)/vdso_test_chacha: $(top_srcdir)/tools/arch/$(ARCH)/vdso/vgetrandom-chacha.S
$(OUTPUT)/vdso_test_chacha: CFLAGS += -idirafter $(top_srcdir)/tools/include \
--
2.46.0
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH v4 4/4] selftests/vDSO: Enable vdso getrandom tests for LoongArch
2024-08-27 13:20 [PATCH v4 0/4] LoongArch: Implement getrandom() in vDSO Xi Ruoyao
` (2 preceding siblings ...)
2024-08-27 13:20 ` [PATCH v4 3/4] selftests/vDSO: Use KHDR_INCLUDES to locate UAPI headers for vdso_test_getrandom Xi Ruoyao
@ 2024-08-27 13:20 ` Xi Ruoyao
2024-08-27 14:00 ` Jason A. Donenfeld
2024-08-27 13:51 ` [PATCH v4 0/4] LoongArch: Implement getrandom() in vDSO Jason A. Donenfeld
4 siblings, 1 reply; 29+ messages in thread
From: Xi Ruoyao @ 2024-08-27 13:20 UTC (permalink / raw)
To: Jason A . Donenfeld, Huacai Chen, WANG Xuerui
Cc: Xi Ruoyao, linux-crypto, loongarch, Jinyang He, Tiezhu Yang,
Arnd Bergmann
Create the symlink to the LoongArch vdso directory, and correct set ARCH
for LoongArch.
Signed-off-by: Xi Ruoyao <xry111@xry111.site>
---
tools/arch/loongarch/vdso | 1 +
tools/testing/selftests/vDSO/Makefile | 4 ++--
2 files changed, 3 insertions(+), 2 deletions(-)
create mode 120000 tools/arch/loongarch/vdso
diff --git a/tools/arch/loongarch/vdso b/tools/arch/loongarch/vdso
new file mode 120000
index 000000000000..ebda43a82db7
--- /dev/null
+++ b/tools/arch/loongarch/vdso
@@ -0,0 +1 @@
+../../../arch/loongarch/vdso
\ No newline at end of file
diff --git a/tools/testing/selftests/vDSO/Makefile b/tools/testing/selftests/vDSO/Makefile
index e346890d4c91..2ad98afce111 100644
--- a/tools/testing/selftests/vDSO/Makefile
+++ b/tools/testing/selftests/vDSO/Makefile
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
uname_M := $(shell uname -m 2>/dev/null || echo not)
-ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/)
+ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/ -e /loongarch/s/[0-9]//g)
SODIUM := $(shell pkg-config --libs --cflags libsodium 2>/dev/null)
TEST_GEN_PROGS := vdso_test_gettimeofday
@@ -11,7 +11,7 @@ ifeq ($(ARCH),$(filter $(ARCH),x86 x86_64))
TEST_GEN_PROGS += vdso_standalone_test_x86
endif
TEST_GEN_PROGS += vdso_test_correctness
-ifeq ($(uname_M),x86_64)
+ifeq ($(uname_M),$(filter $(uname_M),x86_64 loongarch64))
TEST_GEN_PROGS += vdso_test_getrandom
ifneq ($(SODIUM),)
TEST_GEN_PROGS += vdso_test_chacha
--
2.46.0
^ permalink raw reply related [flat|nested] 29+ messages in thread
* Re: [PATCH v4 1/4] LoongArch: vDSO: Wire up getrandom() vDSO implementation
2024-08-27 13:20 ` [PATCH v4 1/4] LoongArch: vDSO: Wire up getrandom() vDSO implementation Xi Ruoyao
@ 2024-08-27 13:36 ` Xi Ruoyao
2024-08-27 13:49 ` Jason A. Donenfeld
` (3 subsequent siblings)
4 siblings, 0 replies; 29+ messages in thread
From: Xi Ruoyao @ 2024-08-27 13:36 UTC (permalink / raw)
To: Jason A . Donenfeld, Huacai Chen, WANG Xuerui
Cc: linux-crypto, loongarch, Jinyang He, Tiezhu Yang, Arnd Bergmann
On Tue, 2024-08-27 at 21:20 +0800, Xi Ruoyao wrote:
> diff --git a/arch/loongarch/kernel/asm-offsets.c b/arch/loongarch/kernel/asm-offsets.c
This change is unneeded now but I forgot to remove it. Will remove it
in v5 but for now just waiting for other review comments.
> index bee9f7a3108f..86f6d8a6dc23 100644
> --- a/arch/loongarch/kernel/asm-offsets.c
> +++ b/arch/loongarch/kernel/asm-offsets.c
> @@ -14,6 +14,7 @@
> #include <asm/ptrace.h>
> #include <asm/processor.h>
> #include <asm/ftrace.h>
> +#include <asm/vdso/vdso.h>
>
> static void __used output_ptreg_defines(void)
> {
> @@ -321,3 +322,12 @@ static void __used output_kvm_defines(void)
> OFFSET(KVM_GPGD, kvm, arch.pgd);
> BLANK();
> }
> +
> +#ifdef CONFIG_VDSO_GETRANDOM
> +static void __used output_vdso_rng_defines(void)
> +{
> + COMMENT("LoongArch VDSO getrandom offsets.");
> + OFFSET(VDSO_RNG_DATA, loongarch_vdso_data, rng_data);
> + BLANK();
> +}
> +#endif
--
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v4 1/4] LoongArch: vDSO: Wire up getrandom() vDSO implementation
2024-08-27 13:20 ` [PATCH v4 1/4] LoongArch: vDSO: Wire up getrandom() vDSO implementation Xi Ruoyao
2024-08-27 13:36 ` Xi Ruoyao
@ 2024-08-27 13:49 ` Jason A. Donenfeld
2024-08-27 14:26 ` Xi Ruoyao
2024-08-27 15:07 ` Xi Ruoyao
` (2 subsequent siblings)
4 siblings, 1 reply; 29+ messages in thread
From: Jason A. Donenfeld @ 2024-08-27 13:49 UTC (permalink / raw)
To: Xi Ruoyao
Cc: Huacai Chen, WANG Xuerui, linux-crypto, loongarch, Jinyang He,
Tiezhu Yang, Arnd Bergmann
On Tue, Aug 27, 2024 at 09:20:14PM +0800, Xi Ruoyao wrote:
> + register long ret asm("a0");
> + register long int nr asm("a7") = __NR_getrandom;
The first line is `long` and the second line is `long int` here. Just
call them both `long` like usual?
> struct loongarch_vdso_data {
> struct vdso_pcpu_data pdata[NR_CPUS];
> +#ifdef CONFIG_VDSO_GETRANDOM
> + struct vdso_rng_data rng_data;
> +#endif
If VSO_GETRANDOM is selected unconditionally for the arch, why the ifdef
here?
> +obj-vdso-$(CONFIG_VDSO_GETRANDOM) += vgetrandom.o vgetrandom-chacha.o
Likewise, same question here.
> + /* copy[3] = "expa" */
> + li.w copy3, 0x6b206574
Might want to mention why you're doing this.
/* copy[3] = "expa", because it was clobbered by the i index. */
Or something like that.
But on the topic of those constants,
> + li.w copy0, 0x61707865
> + li.w copy1, 0x3320646e
> + li.w copy2, 0x79622d32
What if you avoid doing this,
> +
> + ld.w cnt_lo, counter, 0
> + ld.w cnt_hi, counter, 4
> +
> +.Lblock:
> + /* state[0,1,2,3] = "expand 32-byte k" */
> + move state0, copy0
> + move state1, copy1
> + move state2, copy2
Use li.w here with the integer literals,
> + /* copy[3] = "expa" */
> + li.w copy3, 0x6b206574
Skip this,
> + add.w state0, state0, copy0
> + add.w state1, state1, copy1
> + add.w state2, state2, copy2
> + add.w state3, state3, copy3
And then use addi.w here with the integer literals instead?
I don't know anything about loongarch, so just guessing.
BTW, can you confirm that this passes the test in test_vdso_chacha?
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v4 0/4] LoongArch: Implement getrandom() in vDSO
2024-08-27 13:20 [PATCH v4 0/4] LoongArch: Implement getrandom() in vDSO Xi Ruoyao
` (3 preceding siblings ...)
2024-08-27 13:20 ` [PATCH v4 4/4] selftests/vDSO: Enable vdso getrandom tests for LoongArch Xi Ruoyao
@ 2024-08-27 13:51 ` Jason A. Donenfeld
4 siblings, 0 replies; 29+ messages in thread
From: Jason A. Donenfeld @ 2024-08-27 13:51 UTC (permalink / raw)
To: Xi Ruoyao
Cc: Huacai Chen, WANG Xuerui, linux-crypto, loongarch, Jinyang He,
Tiezhu Yang, Arnd Bergmann, tglx
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.
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v4 2/4] selftests/vDSO: Add --cflags for pkg-config command querying libsodium
2024-08-27 13:20 ` [PATCH v4 2/4] selftests/vDSO: Add --cflags for pkg-config command querying libsodium Xi Ruoyao
@ 2024-08-27 13:54 ` Jason A. Donenfeld
0 siblings, 0 replies; 29+ messages in thread
From: Jason A. Donenfeld @ 2024-08-27 13:54 UTC (permalink / raw)
To: Xi Ruoyao
Cc: Huacai Chen, WANG Xuerui, linux-crypto, loongarch, Jinyang He,
Tiezhu Yang, Arnd Bergmann
On Tue, Aug 27, 2024 at 09:20:15PM +0800, Xi Ruoyao wrote:
> When libsodium is installed into its own prefix, the --cflags output is
> needed for the compiler to find libsodium headers.
>
> Signed-off-by: Xi Ruoyao <xry111@xry111.site>
Thanks. I applied this one to random.git. gitolite.kernel.org is down
for maintenance at the moment, but it's in the mirror on my personal
server: https://git.zx2c4.com/linux-rng/
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v4 3/4] selftests/vDSO: Use KHDR_INCLUDES to locate UAPI headers for vdso_test_getrandom
2024-08-27 13:20 ` [PATCH v4 3/4] selftests/vDSO: Use KHDR_INCLUDES to locate UAPI headers for vdso_test_getrandom Xi Ruoyao
@ 2024-08-27 13:58 ` Jason A. Donenfeld
2024-08-27 14:07 ` LEROY Christophe
0 siblings, 1 reply; 29+ messages in thread
From: Jason A. Donenfeld @ 2024-08-27 13:58 UTC (permalink / raw)
To: Xi Ruoyao
Cc: Huacai Chen, WANG Xuerui, linux-crypto, loongarch, Jinyang He,
Tiezhu Yang, Arnd Bergmann, christophe.leroy, tglx,
linux-kselftest
On Tue, Aug 27, 2024 at 09:20:16PM +0800, Xi Ruoyao wrote:
> 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 the
> user space.
Hmm. If I run this on my current 6.10-based system, I get:
$ make
CC vdso_standalone_test_x86
CC vdso_test_getrandom
vdso_test_getrandom.c:43:41: error: field ‘params’ has incomplete type
43 | struct vgetrandom_opaque_params params;
| ^~~~~~
Because KHDR_INCLUDES is /usr/include instead.
Christophe, any suggestions on this one? And any idea why loongarch is
hitting it, but not x86 or ppc?
Jason
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v4 4/4] selftests/vDSO: Enable vdso getrandom tests for LoongArch
2024-08-27 13:20 ` [PATCH v4 4/4] selftests/vDSO: Enable vdso getrandom tests for LoongArch Xi Ruoyao
@ 2024-08-27 14:00 ` Jason A. Donenfeld
2024-08-27 14:45 ` Xi Ruoyao
0 siblings, 1 reply; 29+ messages in thread
From: Jason A. Donenfeld @ 2024-08-27 14:00 UTC (permalink / raw)
To: Xi Ruoyao
Cc: Huacai Chen, WANG Xuerui, linux-crypto, loongarch, Jinyang He,
Tiezhu Yang, Arnd Bergmann
On Tue, Aug 27, 2024 at 09:20:17PM +0800, Xi Ruoyao wrote:
> Create the symlink to the LoongArch vdso directory, and correct set ARCH
> for LoongArch.
FYI, I think you can squash this into your 1/4 commit. Ideally this
whole series reduces down to 1 commit, once I take the two general bug
fixups you're finding.
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v4 3/4] selftests/vDSO: Use KHDR_INCLUDES to locate UAPI headers for vdso_test_getrandom
2024-08-27 13:58 ` Jason A. Donenfeld
@ 2024-08-27 14:07 ` LEROY Christophe
2024-08-27 14:15 ` Jason A. Donenfeld
0 siblings, 1 reply; 29+ messages in thread
From: LEROY Christophe @ 2024-08-27 14:07 UTC (permalink / raw)
To: Jason A. Donenfeld, Xi Ruoyao
Cc: Huacai Chen, WANG Xuerui, linux-crypto@vger.kernel.org,
loongarch@lists.linux.dev, Jinyang He, Tiezhu Yang, Arnd Bergmann,
LEROY Christophe, tglx@linutronix.de,
linux-kselftest@vger.kernel.org
Le 27/08/2024 à 15:58, Jason A. Donenfeld a écrit :
> On Tue, Aug 27, 2024 at 09:20:16PM +0800, Xi Ruoyao wrote:
>> 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 the
>> user space.
>
> Hmm. If I run this on my current 6.10-based system, I get:
>
> $ make
> CC vdso_standalone_test_x86
> CC vdso_test_getrandom
> vdso_test_getrandom.c:43:41: error: field ‘params’ has incomplete type
> 43 | struct vgetrandom_opaque_params params;
> | ^~~~~~
>
> Because KHDR_INCLUDES is /usr/include instead.
>
> Christophe, any suggestions on this one? And any idea why loongarch is
> hitting it, but not x86 or ppc?
>
Can you 'make clean' then provide the output of 'make V=1' ?
On powerpc I get:
$ make ARCH=powerpc CROSS_COMPILE=ppc-linux-
SODIUM="-I/tmp/sodium/usr/local/include/ -L/tmp/sodium/usr/local/lib/
-lsodium" V=1
ppc-linux-gcc -std=gnu99 -D_GNU_SOURCE= vdso_test_gettimeofday.c
parse_vdso.c -o
/home/chleroy/linux-powerpc/tools/testing/selftests/vDSO/vdso_test_gettimeofday
ppc-linux-gcc -std=gnu99 -D_GNU_SOURCE= vdso_test_getcpu.c
parse_vdso.c -o
/home/chleroy/linux-powerpc/tools/testing/selftests/vDSO/vdso_test_getcpu
ppc-linux-gcc -std=gnu99 -D_GNU_SOURCE= vdso_test_abi.c parse_vdso.c
-o /home/chleroy/linux-powerpc/tools/testing/selftests/vDSO/vdso_test_abi
ppc-linux-gcc -std=gnu99 -D_GNU_SOURCE= vdso_test_clock_getres.c -o
/home/chleroy/linux-powerpc/tools/testing/selftests/vDSO/vdso_test_clock_getres
ppc-linux-gcc -std=gnu99 -D_GNU_SOURCE= -ldl vdso_test_correctness.c
-o
/home/chleroy/linux-powerpc/tools/testing/selftests/vDSO/vdso_test_correctness
ppc-linux-gcc -std=gnu99 -D_GNU_SOURCE= -isystem
/home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/include
-isystem
/home/chleroy/linux-powerpc/tools/testing/selftests/../../../include/uapi
vdso_test_getrandom.c parse_vdso.c -o
/home/chleroy/linux-powerpc/tools/testing/selftests/vDSO/vdso_test_getrandom
ppc-linux-gcc -std=gnu99 -D_GNU_SOURCE= -idirafter
/home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/include
-idirafter
/home/chleroy/linux-powerpc/tools/testing/selftests/../../../arch/powerpc/include
-idirafter
/home/chleroy/linux-powerpc/tools/testing/selftests/../../../include
-D__ASSEMBLY__ -DBULID_VDSO -DCONFIG_FUNCTION_ALIGNMENT=0
-Wa,--noexecstack -I/tmp/sodium/usr/local/include/
-L/tmp/sodium/usr/local/lib/ -lsodium vdso_test_chacha.c
/home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/arch/powerpc/vdso/vgetrandom-chacha.S
-o
/home/chleroy/linux-powerpc/tools/testing/selftests/vDSO/vdso_test_chacha
$
Thanks
Christophe
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v4 3/4] selftests/vDSO: Use KHDR_INCLUDES to locate UAPI headers for vdso_test_getrandom
2024-08-27 14:07 ` LEROY Christophe
@ 2024-08-27 14:15 ` Jason A. Donenfeld
2024-08-27 14:41 ` Xi Ruoyao
0 siblings, 1 reply; 29+ messages in thread
From: Jason A. Donenfeld @ 2024-08-27 14:15 UTC (permalink / raw)
To: LEROY Christophe
Cc: Xi Ruoyao, Huacai Chen, WANG Xuerui, linux-crypto@vger.kernel.org,
loongarch@lists.linux.dev, Jinyang He, Tiezhu Yang, Arnd Bergmann,
tglx@linutronix.de, linux-kselftest@vger.kernel.org
On Tue, Aug 27, 2024 at 02:07:59PM +0000, LEROY Christophe wrote:
> Le 27/08/2024 à 15:58, Jason A. Donenfeld a écrit :
> > On Tue, Aug 27, 2024 at 09:20:16PM +0800, Xi Ruoyao wrote:
> >> 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 the
> >> user space.
> >
> > Hmm. If I run this on my current 6.10-based system, I get:
> >
> > $ make
> > CC vdso_standalone_test_x86
> > CC vdso_test_getrandom
> > vdso_test_getrandom.c:43:41: error: field ‘params’ has incomplete type
> > 43 | struct vgetrandom_opaque_params params;
> > | ^~~~~~
> >
> > Because KHDR_INCLUDES is /usr/include instead.
> >
> > Christophe, any suggestions on this one? And any idea why loongarch is
> > hitting it, but not x86 or ppc?
> >
>
>
> Can you 'make clean' then provide the output of 'make V=1' ?
With*out* this patch, the output is:
gcc -std=gnu99 -D_GNU_SOURCE= -isystem /home/zx2c4/Projects/random-linux/tools/testing/selftests/../../../tools/include -isystem /home/zx2c4/Projects/random-linux/tools/testing/selftests/../../../include/uapi vdso_test_getrandom.c parse_vdso.c -o /home/zx2c4/Projects/random-linux/tools/testing/selftests/vDSO/vdso_test_getrandom
*With* this patch, the output is:
gcc -std=gnu99 -D_GNU_SOURCE= -isystem /home/zx2c4/Projects/random-linux/tools/testing/selftests/../../../tools/include -isystem /home/zx2c4/Projects/random-linux/tools/testing/selftests/../../../usr/include vdso_test_getrandom.c parse_vdso.c -o /home/zx2c4/Projects/random-linux/tools/testing/selftests/vDSO/vdso_test_getrandom
vdso_test_getrandom.c:43:41: error: field ‘params’ has incomplete type
43 | struct vgetrandom_opaque_params params;
| ^~~~~~
$ ls /home/zx2c4/Projects/random-linux/tools/testing/selftests/../../../usr/include
headers_check.pl Makefile
Since I don't build in there, this directory is empty.
Jason
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v4 1/4] LoongArch: vDSO: Wire up getrandom() vDSO implementation
2024-08-27 13:49 ` Jason A. Donenfeld
@ 2024-08-27 14:26 ` Xi Ruoyao
2024-08-27 14:30 ` Jason A. Donenfeld
0 siblings, 1 reply; 29+ messages in thread
From: Xi Ruoyao @ 2024-08-27 14:26 UTC (permalink / raw)
To: Jason A. Donenfeld
Cc: Huacai Chen, WANG Xuerui, linux-crypto, loongarch, Jinyang He,
Tiezhu Yang, Arnd Bergmann
On Tue, 2024-08-27 at 15:49 +0200, Jason A. Donenfeld wrote:
> On Tue, Aug 27, 2024 at 09:20:14PM +0800, Xi Ruoyao wrote:
> > + register long ret asm("a0");
> > + register long int nr asm("a7") = __NR_getrandom;
>
> The first line is `long` and the second line is `long int` here. Just
> call them both `long` like usual?
I'll change it.
>
> > struct loongarch_vdso_data {
> > struct vdso_pcpu_data pdata[NR_CPUS];
> > +#ifdef CONFIG_VDSO_GETRANDOM
> > + struct vdso_rng_data rng_data;
> > +#endif
>
> If VSO_GETRANDOM is selected unconditionally for the arch, why the
> ifdef
> here?
>
> > +obj-vdso-$(CONFIG_VDSO_GETRANDOM) += vgetrandom.o vgetrandom-
> > chacha.o
>
> Likewise, same question here.
I'll remove the ifdef and just add them into obj-vdso-y.
> > + /* copy[3] = "expa" */
> > + li.w copy3, 0x6b206574
>
> Might want to mention why you're doing this.
>
> /* copy[3] = "expa", because it was clobbered by the i index. */
I'll add it.
> Or something like that.
>
> But on the topic of those constants,
>
> > + li.w copy0, 0x61707865
> > + li.w copy1, 0x3320646e
> > + li.w copy2, 0x79622d32
>
> What if you avoid doing this,
>
> > +
> > + ld.w cnt_lo, counter, 0
> > + ld.w cnt_hi, counter, 4
> > +
> > +.Lblock:
> > + /* state[0,1,2,3] = "expand 32-byte k" */
> > + move state0, copy0
> > + move state1, copy1
> > + move state2, copy2
>
> Use li.w here with the integer literals,
li.w is expanded to two instructions (lu12i.w + addi.w) by the
assembler.
> > + /* copy[3] = "expa" */
> > + li.w copy3, 0x6b206574
>
> Skip this,
>
> > + add.w state0, state0, copy0
> > + add.w state1, state1, copy1
> > + add.w state2, state2, copy2
> > + add.w state3, state3, copy3
>
> And then use addi.w here with the integer literals instead?
LoongArch addi.w can only handle 12-bit signed immediate values (such a
limitation is very common in RISC machines). On my processor I can
avoid using a register to materialize the constant with addu16i.d +
addu12i.w + addi.w. But there would be 3 instructions, and addu12i.w is
a part of the Loongson Binary Translation extension which is not
available on some processors. Also LBT isn't intended for general use,
so most LBT instructions have a lower throughput than the basic
instructions.
> I don't know anything about loongarch, so just guessing.
> BTW, can you confirm that this passes the test in test_vdso_chacha?
Yes, it has passed the test.
--
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v4 1/4] LoongArch: vDSO: Wire up getrandom() vDSO implementation
2024-08-27 14:26 ` Xi Ruoyao
@ 2024-08-27 14:30 ` Jason A. Donenfeld
0 siblings, 0 replies; 29+ messages in thread
From: Jason A. Donenfeld @ 2024-08-27 14:30 UTC (permalink / raw)
To: Xi Ruoyao
Cc: Huacai Chen, WANG Xuerui, linux-crypto, loongarch, Jinyang He,
Tiezhu Yang, Arnd Bergmann
On Tue, Aug 27, 2024 at 10:26:53PM +0800, Xi Ruoyao wrote:
> > And then use addi.w here with the integer literals instead?
>
> LoongArch addi.w can only handle 12-bit signed immediate values (such a
> limitation is very common in RISC machines). On my processor I can
> avoid using a register to materialize the constant with addu16i.d +
> addu12i.w + addi.w. But there would be 3 instructions, and addu12i.w is
> a part of the Loongson Binary Translation extension which is not
> available on some processors. Also LBT isn't intended for general use,
> so most LBT instructions have a lower throughput than the basic
> instructions.
Very interesting, thanks for the explanation.
Jason
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v4 3/4] selftests/vDSO: Use KHDR_INCLUDES to locate UAPI headers for vdso_test_getrandom
2024-08-27 14:15 ` Jason A. Donenfeld
@ 2024-08-27 14:41 ` Xi Ruoyao
2024-08-27 14:50 ` Christophe Leroy
0 siblings, 1 reply; 29+ messages in thread
From: Xi Ruoyao @ 2024-08-27 14:41 UTC (permalink / raw)
To: Jason A. Donenfeld, LEROY Christophe
Cc: Huacai Chen, WANG Xuerui, linux-crypto@vger.kernel.org,
loongarch@lists.linux.dev, Jinyang He, Tiezhu Yang, Arnd Bergmann,
tglx@linutronix.de, linux-kselftest@vger.kernel.org
On Tue, 2024-08-27 at 16:15 +0200, Jason A. Donenfeld wrote:
/* snip */
> gcc -std=gnu99 -D_GNU_SOURCE= -isystem /home/zx2c4/Projects/random-linux/tools/testing/selftests/../../../tools/include -isystem /home/zx2c4/Projects/random-linux/tools/testing/selftests/../../../usr/include vdso_test_getrandom.c parse_vdso.c -o /home/zx2c4/Projects/random-linux/tools/testing/selftests/vDSO/vdso_test_getrandom
> vdso_test_getrandom.c:43:41: error: field ‘params’ has incomplete type
> 43 | struct vgetrandom_opaque_params params;
> | ^~~~~~
>
> $ ls /home/zx2c4/Projects/random-linux/tools/testing/selftests/../../../usr/include
> headers_check.pl Makefile
>
> Since I don't build in there, this directory is empty.
In the toplevel Makefile:
kselftest-%: headers FORCE
$(Q)$(MAKE) -C $(srctree)/tools/testing/selftests $*
So running "make kselftest-all" to build the self tests should have
already caused make to build the "headers" target, which puts the
headers into usr/include.
I don't think it's supported to build self tests w/o invoking the
toplevel Makefile: many other self tests use KHDR_INCLUDES as well, so
generally building with something like "make -C tools/testing/selftests"
just won't work.
--
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v4 4/4] selftests/vDSO: Enable vdso getrandom tests for LoongArch
2024-08-27 14:00 ` Jason A. Donenfeld
@ 2024-08-27 14:45 ` Xi Ruoyao
0 siblings, 0 replies; 29+ messages in thread
From: Xi Ruoyao @ 2024-08-27 14:45 UTC (permalink / raw)
To: Jason A. Donenfeld
Cc: Huacai Chen, WANG Xuerui, linux-crypto, loongarch, Jinyang He,
Tiezhu Yang, Arnd Bergmann
On Tue, 2024-08-27 at 16:00 +0200, Jason A. Donenfeld wrote:
> On Tue, Aug 27, 2024 at 09:20:17PM +0800, Xi Ruoyao wrote:
> > Create the symlink to the LoongArch vdso directory, and correct set ARCH
> > for LoongArch.
>
> FYI, I think you can squash this into your 1/4 commit. Ideally this
> whole series reduces down to 1 commit, once I take the two general bug
> fixups you're finding.
Ok I'll squash them.
--
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v4 3/4] selftests/vDSO: Use KHDR_INCLUDES to locate UAPI headers for vdso_test_getrandom
2024-08-27 14:41 ` Xi Ruoyao
@ 2024-08-27 14:50 ` Christophe Leroy
2024-08-27 15:00 ` Jason A. Donenfeld
0 siblings, 1 reply; 29+ messages in thread
From: Christophe Leroy @ 2024-08-27 14:50 UTC (permalink / raw)
To: Xi Ruoyao, Jason A. Donenfeld
Cc: Huacai Chen, WANG Xuerui, linux-crypto@vger.kernel.org,
loongarch@lists.linux.dev, Jinyang He, Tiezhu Yang, Arnd Bergmann,
tglx@linutronix.de, linux-kselftest@vger.kernel.org
Le 27/08/2024 à 16:41, Xi Ruoyao a écrit :
> On Tue, 2024-08-27 at 16:15 +0200, Jason A. Donenfeld wrote:
>
> /* snip */
>
>> gcc -std=gnu99 -D_GNU_SOURCE= -isystem /home/zx2c4/Projects/random-linux/tools/testing/selftests/../../../tools/include -isystem /home/zx2c4/Projects/random-linux/tools/testing/selftests/../../../usr/include vdso_test_getrandom.c parse_vdso.c -o /home/zx2c4/Projects/random-linux/tools/testing/selftests/vDSO/vdso_test_getrandom
>> vdso_test_getrandom.c:43:41: error: field ‘params’ has incomplete type
>> 43 | struct vgetrandom_opaque_params params;
>> | ^~~~~~
>>
>> $ ls /home/zx2c4/Projects/random-linux/tools/testing/selftests/../../../usr/include
>> headers_check.pl Makefile
>>
>> Since I don't build in there, this directory is empty.
>
> In the toplevel Makefile:
>
> kselftest-%: headers FORCE
> $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests $*
>
> So running "make kselftest-all" to build the self tests should have
> already caused make to build the "headers" target, which puts the
> headers into usr/include.
>
> I don't think it's supported to build self tests w/o invoking the
> toplevel Makefile: many other self tests use KHDR_INCLUDES as well, so
> generally building with something like "make -C tools/testing/selftests"
> just won't work.
>
My usr/include/ is also empty (only Makefile and headers_check.pl) and
building directly in tools/testing/selftests/vDSO works for me.
The command is:
ppc-linux-gcc -std=gnu99 -D_GNU_SOURCE= -isystem
/home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/include
-isystem
/home/chleroy/linux-powerpc/tools/testing/selftests/../../../include/uapi
vdso_test_getrandom.c parse_vdso.c -o
/home/chleroy/linux-powerpc/tools/testing/selftests/vDSO/vdso_test_getrandom
I believe I get the needed headers through : -isystem
/home/chleroy/linux-powerpc/tools/testing/selftests/../../../include/uapi
Christophe
PS: By the way, did you see the -DBULID_VDSO for the chacha test ? Don't
know the impact though ....
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v4 3/4] selftests/vDSO: Use KHDR_INCLUDES to locate UAPI headers for vdso_test_getrandom
2024-08-27 14:50 ` Christophe Leroy
@ 2024-08-27 15:00 ` Jason A. Donenfeld
2024-08-27 15:05 ` Xi Ruoyao
2024-08-27 15:12 ` Christophe Leroy
0 siblings, 2 replies; 29+ messages in thread
From: Jason A. Donenfeld @ 2024-08-27 15:00 UTC (permalink / raw)
To: Christophe Leroy
Cc: Xi Ruoyao, Huacai Chen, WANG Xuerui, linux-crypto@vger.kernel.org,
loongarch@lists.linux.dev, Jinyang He, Tiezhu Yang, Arnd Bergmann,
tglx@linutronix.de, linux-kselftest@vger.kernel.org
On Tue, Aug 27, 2024 at 04:50:59PM +0200, Christophe Leroy wrote:
>
>
> Le 27/08/2024 à 16:41, Xi Ruoyao a écrit :
> > On Tue, 2024-08-27 at 16:15 +0200, Jason A. Donenfeld wrote:
> >
> > /* snip */
> >
> >> gcc -std=gnu99 -D_GNU_SOURCE= -isystem /home/zx2c4/Projects/random-linux/tools/testing/selftests/../../../tools/include -isystem /home/zx2c4/Projects/random-linux/tools/testing/selftests/../../../usr/include vdso_test_getrandom.c parse_vdso.c -o /home/zx2c4/Projects/random-linux/tools/testing/selftests/vDSO/vdso_test_getrandom
> >> vdso_test_getrandom.c:43:41: error: field ‘params’ has incomplete type
> >> 43 | struct vgetrandom_opaque_params params;
> >> | ^~~~~~
> >>
> >> $ ls /home/zx2c4/Projects/random-linux/tools/testing/selftests/../../../usr/include
> >> headers_check.pl Makefile
> >>
> >> Since I don't build in there, this directory is empty.
> >
> > In the toplevel Makefile:
> >
> > kselftest-%: headers FORCE
> > $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests $*
> >
> > So running "make kselftest-all" to build the self tests should have
> > already caused make to build the "headers" target, which puts the
> > headers into usr/include.
> >
> > I don't think it's supported to build self tests w/o invoking the
> > toplevel Makefile: many other self tests use KHDR_INCLUDES as well, so
> > generally building with something like "make -C tools/testing/selftests"
> > just won't work.
> >
>
> My usr/include/ is also empty (only Makefile and headers_check.pl) and
> building directly in tools/testing/selftests/vDSO works for me.
>
> The command is:
>
> ppc-linux-gcc -std=gnu99 -D_GNU_SOURCE= -isystem
> /home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/include
> -isystem
> /home/chleroy/linux-powerpc/tools/testing/selftests/../../../include/uapi
> vdso_test_getrandom.c parse_vdso.c -o
> /home/chleroy/linux-powerpc/tools/testing/selftests/vDSO/vdso_test_getrandom
>
> I believe I get the needed headers through : -isystem
> /home/chleroy/linux-powerpc/tools/testing/selftests/../../../include/uapi
The effect of this patch is to replace include/uapi with usr/include, so
it will break for you too.
What I'm wondering is why yours and mine work like that, while Ruoyao's
breaks. He makes a good argument as to why this patch is the "right
way", even if it breaks our workflow...
>
> Christophe
>
> PS: By the way, did you see the -DBULID_VDSO for the chacha test ? Don't
> know the impact though ....
Yes and https://lore.kernel.org/all/20240827145454.3317093-1-Jason@zx2c4.com/
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v4 3/4] selftests/vDSO: Use KHDR_INCLUDES to locate UAPI headers for vdso_test_getrandom
2024-08-27 15:00 ` Jason A. Donenfeld
@ 2024-08-27 15:05 ` Xi Ruoyao
2024-08-27 15:10 ` Jason A. Donenfeld
2024-08-27 15:12 ` Christophe Leroy
1 sibling, 1 reply; 29+ messages in thread
From: Xi Ruoyao @ 2024-08-27 15:05 UTC (permalink / raw)
To: Jason A. Donenfeld, Christophe Leroy
Cc: Huacai Chen, WANG Xuerui, linux-crypto@vger.kernel.org,
loongarch@lists.linux.dev, Jinyang He, Tiezhu Yang, Arnd Bergmann,
tglx@linutronix.de, linux-kselftest@vger.kernel.org
On Tue, 2024-08-27 at 17:00 +0200, Jason A. Donenfeld wrote:
> The effect of this patch is to replace include/uapi with usr/include, so
> it will break for you too.
>
> What I'm wondering is why yours and mine work like that, while Ruoyao's
> breaks. He makes a good argument as to why this patch is the "right
> way", even if it breaks our workflow...
Because arch/loongarch/include/uapi/asm/sigcontext.h includes
<linux/posix_types.h>, but the files for x86 and ppc do not.
I cannot see how this inclusion is useful anyway, so maybe I can just
remove the inclusion and paper over the real issue for now?
--
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v4 1/4] LoongArch: vDSO: Wire up getrandom() vDSO implementation
2024-08-27 13:20 ` [PATCH v4 1/4] LoongArch: vDSO: Wire up getrandom() vDSO implementation Xi Ruoyao
2024-08-27 13:36 ` Xi Ruoyao
2024-08-27 13:49 ` Jason A. Donenfeld
@ 2024-08-27 15:07 ` Xi Ruoyao
2024-08-28 14:26 ` Jason A. Donenfeld
2024-08-28 14:33 ` Jason A. Donenfeld
4 siblings, 0 replies; 29+ messages in thread
From: Xi Ruoyao @ 2024-08-27 15:07 UTC (permalink / raw)
To: Jason A . Donenfeld, Huacai Chen, WANG Xuerui
Cc: linux-crypto, loongarch, Jinyang He, Tiezhu Yang, Arnd Bergmann
On Tue, 2024-08-27 at 21:20 +0800, Xi Ruoyao wrote:
> diff --git a/arch/loongarch/vdso/vgetrandom.c b/arch/loongarch/vdso/vgetrandom.c
> new file mode 100644
> index 000000000000..b9142a5b5d77
> --- /dev/null
> +++ b/arch/loongarch/vdso/vgetrandom.c
> @@ -0,0 +1,12 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (C) 2024 Xi Ruoyao <xry111@xry111.site>. All Rights Reserved.
> + */
> +#include <linux/types.h>
> +
> +ssize_t __vdso_getrandom(void *buffer, size_t len, unsigned int flags,
> + void *opaque_state, size_t opaque_len)
Self note: I got a -Wmissing-prototype warning here and it needs to be
fixed in v4. I had
> +{
> + return __cvdso_getrandom(buffer, len, flags, opaque_state,
> + opaque_len);
> +}
--
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v4 3/4] selftests/vDSO: Use KHDR_INCLUDES to locate UAPI headers for vdso_test_getrandom
2024-08-27 15:05 ` Xi Ruoyao
@ 2024-08-27 15:10 ` Jason A. Donenfeld
2024-08-27 15:28 ` Xi Ruoyao
0 siblings, 1 reply; 29+ messages in thread
From: Jason A. Donenfeld @ 2024-08-27 15:10 UTC (permalink / raw)
To: Xi Ruoyao
Cc: Christophe Leroy, Huacai Chen, WANG Xuerui,
linux-crypto@vger.kernel.org, loongarch@lists.linux.dev,
Jinyang He, Tiezhu Yang, Arnd Bergmann, tglx@linutronix.de,
linux-kselftest@vger.kernel.org
On Tue, Aug 27, 2024 at 11:05:14PM +0800, Xi Ruoyao wrote:
> On Tue, 2024-08-27 at 17:00 +0200, Jason A. Donenfeld wrote:
> > The effect of this patch is to replace include/uapi with usr/include, so
> > it will break for you too.
> >
> > What I'm wondering is why yours and mine work like that, while Ruoyao's
> > breaks. He makes a good argument as to why this patch is the "right
> > way", even if it breaks our workflow...
>
> Because arch/loongarch/include/uapi/asm/sigcontext.h includes
> <linux/posix_types.h>, but the files for x86 and ppc do not.
>
> I cannot see how this inclusion is useful anyway, so maybe I can just
> remove the inclusion and paper over the real issue for now?
The kselftest people might disagree with papering it over and may prefer
your patch, but your solution does sound better to me...
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v4 3/4] selftests/vDSO: Use KHDR_INCLUDES to locate UAPI headers for vdso_test_getrandom
2024-08-27 15:00 ` Jason A. Donenfeld
2024-08-27 15:05 ` Xi Ruoyao
@ 2024-08-27 15:12 ` Christophe Leroy
1 sibling, 0 replies; 29+ messages in thread
From: Christophe Leroy @ 2024-08-27 15:12 UTC (permalink / raw)
To: Jason A. Donenfeld
Cc: Xi Ruoyao, Huacai Chen, WANG Xuerui, linux-crypto@vger.kernel.org,
loongarch@lists.linux.dev, Jinyang He, Tiezhu Yang, Arnd Bergmann,
tglx@linutronix.de, linux-kselftest@vger.kernel.org
Le 27/08/2024 à 17:00, Jason A. Donenfeld a écrit :
> On Tue, Aug 27, 2024 at 04:50:59PM +0200, Christophe Leroy wrote:
>>
>>
>> Le 27/08/2024 à 16:41, Xi Ruoyao a écrit :
>>> On Tue, 2024-08-27 at 16:15 +0200, Jason A. Donenfeld wrote:
>>>
>>> /* snip */
>>>
>>>> gcc -std=gnu99 -D_GNU_SOURCE= -isystem /home/zx2c4/Projects/random-linux/tools/testing/selftests/../../../tools/include -isystem /home/zx2c4/Projects/random-linux/tools/testing/selftests/../../../usr/include vdso_test_getrandom.c parse_vdso.c -o /home/zx2c4/Projects/random-linux/tools/testing/selftests/vDSO/vdso_test_getrandom
>>>> vdso_test_getrandom.c:43:41: error: field ‘params’ has incomplete type
>>>> 43 | struct vgetrandom_opaque_params params;
>>>> | ^~~~~~
>>>>
>>>> $ ls /home/zx2c4/Projects/random-linux/tools/testing/selftests/../../../usr/include
>>>> headers_check.pl Makefile
>>>>
>>>> Since I don't build in there, this directory is empty.
>>>
>>> In the toplevel Makefile:
>>>
>>> kselftest-%: headers FORCE
>>> $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests $*
>>>
>>> So running "make kselftest-all" to build the self tests should have
>>> already caused make to build the "headers" target, which puts the
>>> headers into usr/include.
>>>
>>> I don't think it's supported to build self tests w/o invoking the
>>> toplevel Makefile: many other self tests use KHDR_INCLUDES as well, so
>>> generally building with something like "make -C tools/testing/selftests"
>>> just won't work.
>>>
>>
>> My usr/include/ is also empty (only Makefile and headers_check.pl) and
>> building directly in tools/testing/selftests/vDSO works for me.
>>
>> The command is:
>>
>> ppc-linux-gcc -std=gnu99 -D_GNU_SOURCE= -isystem
>> /home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/include
>> -isystem
>> /home/chleroy/linux-powerpc/tools/testing/selftests/../../../include/uapi
>> vdso_test_getrandom.c parse_vdso.c -o
>> /home/chleroy/linux-powerpc/tools/testing/selftests/vDSO/vdso_test_getrandom
>>
>> I believe I get the needed headers through : -isystem
>> /home/chleroy/linux-powerpc/tools/testing/selftests/../../../include/uapi
>
> The effect of this patch is to replace include/uapi with usr/include, so
> it will break for you too.
>
> What I'm wondering is why yours and mine work like that, while Ruoyao's
> breaks. He makes a good argument as to why this patch is the "right
> way", even if it breaks our workflow...
Ah yes he is probably right.
Then I'll have to first do:
make CROSS_COMPILE=powerpc64-linux- ARCH=powerpc headers
Then everything should be fine.
Christophe
>
>>
>> Christophe
>>
>> PS: By the way, did you see the -DBULID_VDSO for the chacha test ? Don't
>> know the impact though ....
>
> Yes and https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fall%2F20240827145454.3317093-1-Jason%40zx2c4.com%2F&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C627846cc0a0e429e45c508dcc6a90690%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638603676502990226%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=H7PPFv8QGHsb9xh3J%2FzyeFrpvDu2uSKqx4ZwrPNwC2s%3D&reserved=0
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v4 3/4] selftests/vDSO: Use KHDR_INCLUDES to locate UAPI headers for vdso_test_getrandom
2024-08-27 15:10 ` Jason A. Donenfeld
@ 2024-08-27 15:28 ` Xi Ruoyao
2024-08-27 15:29 ` Jason A. Donenfeld
0 siblings, 1 reply; 29+ messages in thread
From: Xi Ruoyao @ 2024-08-27 15:28 UTC (permalink / raw)
To: Jason A. Donenfeld
Cc: Christophe Leroy, Huacai Chen, WANG Xuerui,
linux-crypto@vger.kernel.org, loongarch@lists.linux.dev,
Jinyang He, Tiezhu Yang, Arnd Bergmann, tglx@linutronix.de,
linux-kselftest@vger.kernel.org
On Tue, 2024-08-27 at 17:10 +0200, Jason A. Donenfeld wrote:
> On Tue, Aug 27, 2024 at 11:05:14PM +0800, Xi Ruoyao wrote:
> > On Tue, 2024-08-27 at 17:00 +0200, Jason A. Donenfeld wrote:
> > > The effect of this patch is to replace include/uapi with usr/include, so
> > > it will break for you too.
> > >
> > > What I'm wondering is why yours and mine work like that, while Ruoyao's
> > > breaks. He makes a good argument as to why this patch is the "right
> > > way", even if it breaks our workflow...
> >
> > Because arch/loongarch/include/uapi/asm/sigcontext.h includes
> > <linux/posix_types.h>, but the files for x86 and ppc do not.
> >
> > I cannot see how this inclusion is useful anyway, so maybe I can just
> > remove the inclusion and paper over the real issue for now?
>
> The kselftest people might disagree with papering it over and may prefer
> your patch, but your solution does sound better to me...
Oops the papering over does not really work because the compiler picks
up the sigcontext.h already installed to /usr/include/asm/sigcontext.h.
So, if we want to use the "updated" version of sigcontext.h, we still
have to add KHDR_INCLUDES to pick up
kernel-tree/usr/include/asm/sigcontext.h instead.
Or, I can add $(KHDR_INCLUDES) but also keep
-isystem $(top_srcdir)/include/uapi, so "make -C tools/testing/selftests
TARGETS=vDSO" will still (happens to) work on x86 and ppc (without
headers in kernel-tree/usr).
If you agree I'll use this approach in v5.
--
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v4 3/4] selftests/vDSO: Use KHDR_INCLUDES to locate UAPI headers for vdso_test_getrandom
2024-08-27 15:28 ` Xi Ruoyao
@ 2024-08-27 15:29 ` Jason A. Donenfeld
2024-08-28 11:36 ` Jason A. Donenfeld
0 siblings, 1 reply; 29+ messages in thread
From: Jason A. Donenfeld @ 2024-08-27 15:29 UTC (permalink / raw)
To: Xi Ruoyao
Cc: Christophe Leroy, Huacai Chen, WANG Xuerui,
linux-crypto@vger.kernel.org, loongarch@lists.linux.dev,
Jinyang He, Tiezhu Yang, Arnd Bergmann, tglx@linutronix.de,
linux-kselftest@vger.kernel.org
On Tue, Aug 27, 2024 at 5:29 PM Xi Ruoyao <xry111@xry111.site> wrote:
> Or, I can add $(KHDR_INCLUDES) but also keep
> -isystem $(top_srcdir)/include/uapi, so "make -C tools/testing/selftests
> TARGETS=vDSO" will still (happens to) work on x86 and ppc (without
> headers in kernel-tree/usr).
Oh, the porquenolosdos solution. That sounds good to me.
Jason
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v4 3/4] selftests/vDSO: Use KHDR_INCLUDES to locate UAPI headers for vdso_test_getrandom
2024-08-27 15:29 ` Jason A. Donenfeld
@ 2024-08-28 11:36 ` Jason A. Donenfeld
2024-08-28 12:00 ` Xi Ruoyao
0 siblings, 1 reply; 29+ messages in thread
From: Jason A. Donenfeld @ 2024-08-28 11:36 UTC (permalink / raw)
To: Xi Ruoyao
Cc: Christophe Leroy, Huacai Chen, WANG Xuerui,
linux-crypto@vger.kernel.org, loongarch@lists.linux.dev,
Jinyang He, Tiezhu Yang, Arnd Bergmann, tglx@linutronix.de,
linux-kselftest@vger.kernel.org
On Tue, Aug 27, 2024 at 05:29:56PM +0200, Jason A. Donenfeld wrote:
> On Tue, Aug 27, 2024 at 5:29 PM Xi Ruoyao <xry111@xry111.site> wrote:
> > Or, I can add $(KHDR_INCLUDES) but also keep
> > -isystem $(top_srcdir)/include/uapi, so "make -C tools/testing/selftests
> > TARGETS=vDSO" will still (happens to) work on x86 and ppc (without
> > headers in kernel-tree/usr).
>
> Oh, the porquenolosdos solution. That sounds good to me.
Does the below work for you?
From 0a769491e0193cdf9728a23d02be5e6be975b513 Mon Sep 17 00:00:00 2001
From: Xi Ruoyao <xry111@xry111.site>
Date: Wed, 28 Aug 2024 13:29:57 +0200
Subject: [PATCH] selftests/vDSO: use KHDR_INCLUDES to locate UAPI headers for
vdso_test_getrandom
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: Xi Ruoyao <xry111@xry111.site>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
tools/testing/selftests/vDSO/Makefile | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/testing/selftests/vDSO/Makefile b/tools/testing/selftests/vDSO/Makefile
index d1452c7d6d4f..13a626ef64f7 100644
--- a/tools/testing/selftests/vDSO/Makefile
+++ b/tools/testing/selftests/vDSO/Makefile
@@ -39,6 +39,7 @@ $(OUTPUT)/vdso_test_correctness: LDFLAGS += -ldl
$(OUTPUT)/vdso_test_getrandom: parse_vdso.c
$(OUTPUT)/vdso_test_getrandom: CFLAGS += -isystem $(top_srcdir)/tools/include \
+ $(KHDR_INCLUDES) \
-isystem $(top_srcdir)/include/uapi
$(OUTPUT)/vdso_test_chacha: $(top_srcdir)/tools/arch/$(ARCH)/vdso/vgetrandom-chacha.S
--
2.46.0
^ permalink raw reply related [flat|nested] 29+ messages in thread
* Re: [PATCH v4 3/4] selftests/vDSO: Use KHDR_INCLUDES to locate UAPI headers for vdso_test_getrandom
2024-08-28 11:36 ` Jason A. Donenfeld
@ 2024-08-28 12:00 ` Xi Ruoyao
0 siblings, 0 replies; 29+ messages in thread
From: Xi Ruoyao @ 2024-08-28 12:00 UTC (permalink / raw)
To: Jason A. Donenfeld
Cc: Christophe Leroy, Huacai Chen, WANG Xuerui,
linux-crypto@vger.kernel.org, loongarch@lists.linux.dev,
Jinyang He, Tiezhu Yang, Arnd Bergmann, tglx@linutronix.de,
linux-kselftest@vger.kernel.org
On Wed, 2024-08-28 at 13:36 +0200, Jason A. Donenfeld wrote:
> On Tue, Aug 27, 2024 at 05:29:56PM +0200, Jason A. Donenfeld wrote:
> > On Tue, Aug 27, 2024 at 5:29 PM Xi Ruoyao <xry111@xry111.site> wrote:
> > > Or, I can add $(KHDR_INCLUDES) but also keep
> > > -isystem $(top_srcdir)/include/uapi, so "make -C tools/testing/selftests
> > > TARGETS=vDSO" will still (happens to) work on x86 and ppc (without
> > > headers in kernel-tree/usr).
> >
> > Oh, the porquenolosdos solution. That sounds good to me.
>
>
> Does the below work for you?
Yes, it works.
> From 0a769491e0193cdf9728a23d02be5e6be975b513 Mon Sep 17 00:00:00 2001
> From: Xi Ruoyao <xry111@xry111.site>
> Date: Wed, 28 Aug 2024 13:29:57 +0200
> Subject: [PATCH] selftests/vDSO: use KHDR_INCLUDES to locate UAPI headers for
> vdso_test_getrandom
>
> 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: Xi Ruoyao <xry111@xry111.site>
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> ---
> tools/testing/selftests/vDSO/Makefile | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/tools/testing/selftests/vDSO/Makefile b/tools/testing/selftests/vDSO/Makefile
> index d1452c7d6d4f..13a626ef64f7 100644
> --- a/tools/testing/selftests/vDSO/Makefile
> +++ b/tools/testing/selftests/vDSO/Makefile
> @@ -39,6 +39,7 @@ $(OUTPUT)/vdso_test_correctness: LDFLAGS += -ldl
>
> $(OUTPUT)/vdso_test_getrandom: parse_vdso.c
> $(OUTPUT)/vdso_test_getrandom: CFLAGS += -isystem $(top_srcdir)/tools/include \
> + $(KHDR_INCLUDES) \
> -isystem $(top_srcdir)/include/uapi
>
> $(OUTPUT)/vdso_test_chacha: $(top_srcdir)/tools/arch/$(ARCH)/vdso/vgetrandom-chacha.S
> --
> 2.46.0
>
>
--
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v4 1/4] LoongArch: vDSO: Wire up getrandom() vDSO implementation
2024-08-27 13:20 ` [PATCH v4 1/4] LoongArch: vDSO: Wire up getrandom() vDSO implementation Xi Ruoyao
` (2 preceding siblings ...)
2024-08-27 15:07 ` Xi Ruoyao
@ 2024-08-28 14:26 ` Jason A. Donenfeld
2024-08-28 14:33 ` Jason A. Donenfeld
4 siblings, 0 replies; 29+ messages in thread
From: Jason A. Donenfeld @ 2024-08-28 14:26 UTC (permalink / raw)
To: Xi Ruoyao
Cc: Huacai Chen, WANG Xuerui, linux-crypto, loongarch, Jinyang He,
Tiezhu Yang, Arnd Bergmann
On Tue, Aug 27, 2024 at 09:20:14PM +0800, Xi Ruoyao wrote:
> diff --git a/arch/loongarch/vdso/vgetrandom-chacha.S b/arch/loongarch/vdso/vgetrandom-chacha.S
> new file mode 100644
> index 000000000000..2e42198f2faf
> --- /dev/null
> +++ b/arch/loongarch/vdso/vgetrandom-chacha.S
> @@ -0,0 +1,239 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (C) 2024 Xi Ruoyao <xry111@xry111.site>. All Rights Reserved.
> + */
> +
> +#include <asm/asm.h>
> +#include <asm/regdef.h>
> +#include <linux/linkage.h>
> +
> +.text
> +
> +/* Salsa20 quarter-round */
> +.macro QR a b c d
> + add.w \a, \a, \b
> + xor \d, \d, \a
> + rotri.w \d, \d, 16
> +
> + add.w \c, \c, \d
> + xor \b, \b, \c
> + rotri.w \b, \b, 20
> +
> + add.w \a, \a, \b
> + xor \d, \d, \a
> + rotri.w \d, \d, 24
> +
> + add.w \c, \c, \d
> + xor \b, \b, \c
> + rotri.w \b, \b, 25
> +.endm
> +
> +/*
> + * Very basic LoongArch implementation of ChaCha20. Produces a given positive
> + * number of blocks of output with a nonce of 0, taking an input key and
> + * 8-byte counter. Importantly does not spill to the stack. Its arguments
> + * are:
> + *
> + * a0: output bytes
> + * a1: 32-byte key input
> + * a2: 8-byte counter input/output
> + * a3: number of 64-byte blocks to write to output
> + */
> +SYM_FUNC_START(__arch_chacha20_blocks_nostack)
I can confirm this works:
$ loongarch64-unknown-linux-gnu-gcc -std=gnu99 -D_GNU_SOURCE= -idirafter tools/testing/selftests/../../../tools/include -idirafter tools/testing/selftests/../../../arch/loongarch/include -idirafter tools/testing/selftests/../../../include -D__ASSEMBLY__ -Wa,--noexecstack vdso_test_chacha.c tools/testing/selftests/../../../tools/arch/loongarch/vdso/vgetrandom-chacha.S -o tools/testing/selftests/vDSO/vdso_test_chacha -static
$ qemu-loongarch64 ./vdso_test_chacha
TAP version 13
1..1
ok 1 chacha: PASS
Just waiting now on a v5 as discussed and acks from the LoongArch maintainers on that v5.
Jason
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v4 1/4] LoongArch: vDSO: Wire up getrandom() vDSO implementation
2024-08-27 13:20 ` [PATCH v4 1/4] LoongArch: vDSO: Wire up getrandom() vDSO implementation Xi Ruoyao
` (3 preceding siblings ...)
2024-08-28 14:26 ` Jason A. Donenfeld
@ 2024-08-28 14:33 ` Jason A. Donenfeld
4 siblings, 0 replies; 29+ messages in thread
From: Jason A. Donenfeld @ 2024-08-28 14:33 UTC (permalink / raw)
To: Xi Ruoyao
Cc: Huacai Chen, WANG Xuerui, linux-crypto, loongarch, Jinyang He,
Tiezhu Yang, Arnd Bergmann
On Tue, Aug 27, 2024 at 09:20:14PM +0800, Xi Ruoyao wrote:
> +extern void __arch_chacha20_blocks_nostack(u8 *dst_bytes, const u32 *key,
> + u32 *counter, size_t nblocks);
As of the latest master, the forward declaration here isn't necessary.
^ permalink raw reply [flat|nested] 29+ messages in thread
end of thread, other threads:[~2024-08-28 14:33 UTC | newest]
Thread overview: 29+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-27 13:20 [PATCH v4 0/4] LoongArch: Implement getrandom() in vDSO Xi Ruoyao
2024-08-27 13:20 ` [PATCH v4 1/4] LoongArch: vDSO: Wire up getrandom() vDSO implementation Xi Ruoyao
2024-08-27 13:36 ` Xi Ruoyao
2024-08-27 13:49 ` Jason A. Donenfeld
2024-08-27 14:26 ` Xi Ruoyao
2024-08-27 14:30 ` Jason A. Donenfeld
2024-08-27 15:07 ` Xi Ruoyao
2024-08-28 14:26 ` Jason A. Donenfeld
2024-08-28 14:33 ` Jason A. Donenfeld
2024-08-27 13:20 ` [PATCH v4 2/4] selftests/vDSO: Add --cflags for pkg-config command querying libsodium Xi Ruoyao
2024-08-27 13:54 ` Jason A. Donenfeld
2024-08-27 13:20 ` [PATCH v4 3/4] selftests/vDSO: Use KHDR_INCLUDES to locate UAPI headers for vdso_test_getrandom Xi Ruoyao
2024-08-27 13:58 ` Jason A. Donenfeld
2024-08-27 14:07 ` LEROY Christophe
2024-08-27 14:15 ` Jason A. Donenfeld
2024-08-27 14:41 ` Xi Ruoyao
2024-08-27 14:50 ` Christophe Leroy
2024-08-27 15:00 ` Jason A. Donenfeld
2024-08-27 15:05 ` Xi Ruoyao
2024-08-27 15:10 ` Jason A. Donenfeld
2024-08-27 15:28 ` Xi Ruoyao
2024-08-27 15:29 ` Jason A. Donenfeld
2024-08-28 11:36 ` Jason A. Donenfeld
2024-08-28 12:00 ` Xi Ruoyao
2024-08-27 15:12 ` Christophe Leroy
2024-08-27 13:20 ` [PATCH v4 4/4] selftests/vDSO: Enable vdso getrandom tests for LoongArch Xi Ruoyao
2024-08-27 14:00 ` Jason A. Donenfeld
2024-08-27 14:45 ` Xi Ruoyao
2024-08-27 13:51 ` [PATCH v4 0/4] LoongArch: Implement getrandom() in vDSO Jason A. Donenfeld
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).