@@ -17,6 +17,7 @@
#include <linux/time_namespace.h>
#include <linux/timekeeper_internal.h>
+#include <asm/alternative.h>
#include <asm/page.h>
#include <asm/vdso.h>
#include <vdso/helpers.h>
@@ -105,7 +106,7 @@ struct loongarch_vdso_info vdso_info = {
static int __init init_vdso(void)
{
- unsigned long i, cpu, pfn;
+ unsigned long i, cpu, pfn, vdso;
BUG_ON(!PAGE_ALIGNED(vdso_info.vdso));
BUG_ON(!PAGE_ALIGNED(vdso_info.size));
@@ -117,6 +118,11 @@ static int __init init_vdso(void)
for (i = 0; i < vdso_info.size / PAGE_SIZE; i++)
vdso_info.code_mapping.pages[i] = pfn_to_page(pfn + i);
+ vdso = (unsigned long)vdso_info.vdso;
+
+ apply_alternatives((struct alt_instr *)(vdso + vdso_offset_alt),
+ (struct alt_instr *)(vdso + vdso_offset_alt_end));
+
return 0;
}
subsys_initcall(init_vdso);
@@ -35,6 +35,12 @@ SECTIONS
.rodata : { *(.rodata*) } :text
+ .altinstructions : ALIGN(4) {
+ VDSO_alt = .;
+ *(.altinstructions)
+ VDSO_alt_end = .;
+ } :text
+
_end = .;
PROVIDE(end = .);
To implement getrandom() in vDSO, we need to implement stack-less ChaCha20. ChaCha20 is designed to be SIMD-friendly, but LSX is not guaranteed to be available on all LoongArch CPU models. Perform alternative runtime patching on vDSO so we'll be able to use LSX in vDSO. Signed-off-by: Xi Ruoyao <xry111@xry111.site> --- arch/loongarch/kernel/vdso.c | 8 +++++++- arch/loongarch/vdso/vdso.lds.S | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-)