git: 4e34c0445c40 - stable/13 - linux(4): Fixup the vDSO initialization order.

From: Dmitry Chagin <dchagin_at_FreeBSD.org>
Date: Fri, 17 Jun 2022 19:36:55 UTC
The branch stable/13 has been updated by dchagin:

URL: https://cgit.FreeBSD.org/src/commit/?id=4e34c0445c4084a17444691f22146af4ba28bf52

commit 4e34c0445c4084a17444691f22146af4ba28bf52
Author:     Dmitry Chagin <dchagin@FreeBSD.org>
AuthorDate: 2021-07-20 07:02:34 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2022-06-17 19:33:07 +0000

    linux(4): Fixup the vDSO initialization order.
    
    The vDSO initialisation order should be as follows:
    - native abi init via exec_sysvec_init();
    - vDSO symbols queued to the linux_vdso_syms list;
    - linux_vdso_install();
    - linux_exec_sysvec_init();
    
    As the exec_sysvec_init() called with SI_ORDER_ANY (last) at SI_SUB_EXEC
    order, move linux_vdso_install() and linux_exec_sysvec_init() to the
    SI_SUB_EXEC+1 order.
    
    Reviewed by:            trasz
    Differential Revision:  https://reviews.freebsd.org/D30902
    MFC after               2 weeks
    
    (cherry picked from commit 09cffde975b87b293457c9a228cb980ec729384a)
---
 sys/amd64/linux/linux_sysvec.c     |  8 ++++++--
 sys/amd64/linux32/linux32_sysvec.c |  8 ++++++--
 sys/arm64/linux/linux_sysvec.c     |  8 ++++++--
 sys/i386/linux/linux_sysvec.c      | 13 +++++++++++--
 4 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/sys/amd64/linux/linux_sysvec.c b/sys/amd64/linux/linux_sysvec.c
index 092452366fba..d3e8ce5ad035 100644
--- a/sys/amd64/linux/linux_sysvec.c
+++ b/sys/amd64/linux/linux_sysvec.c
@@ -798,6 +798,10 @@ linux_on_exec_vmspace(struct proc *p, struct image_params *imgp)
 	return (error);
 }
 
+/*
+ * linux_vdso_install() and linux_exec_sysvec_init() must be called
+ * after exec_sysvec_init() which is SI_SUB_EXEC (SI_ORDER_ANY).
+ */
 static void
 linux_exec_sysvec_init(void *param)
 {
@@ -820,7 +824,7 @@ linux_exec_sysvec_init(void *param)
 	if (bootverbose)
 		printf("Linux x86-64 vDSO tsc_selector: %lu\n", *ktsc_selector);
 }
-SYSINIT(elf_linux_exec_sysvec_init, SI_SUB_EXEC, SI_ORDER_ANY,
+SYSINIT(elf_linux_exec_sysvec_init, SI_SUB_EXEC + 1, SI_ORDER_ANY,
     linux_exec_sysvec_init, &elf_linux_sysvec);
 
 static void
@@ -844,7 +848,7 @@ linux_vdso_install(const void *param)
 
 	linux_vdso_reloc(linux_vdso_mapping, linux_vdso_base);
 }
-SYSINIT(elf_linux_vdso_init, SI_SUB_EXEC, SI_ORDER_FIRST,
+SYSINIT(elf_linux_vdso_init, SI_SUB_EXEC + 1, SI_ORDER_FIRST,
     linux_vdso_install, NULL);
 
 static void
diff --git a/sys/amd64/linux32/linux32_sysvec.c b/sys/amd64/linux32/linux32_sysvec.c
index a97ac7337120..d94ee6c87fd6 100644
--- a/sys/amd64/linux32/linux32_sysvec.c
+++ b/sys/amd64/linux32/linux32_sysvec.c
@@ -961,6 +961,10 @@ linux_on_exec_vmspace(struct proc *p, struct image_params *imgp)
 	return (error);
 }
 
+/*
+ * linux_vdso_install() and linux_exec_sysvec_init() must be called
+ * after exec_sysvec_init() which is SI_SUB_EXEC (SI_ORDER_ANY).
+ */
 static void
 linux_exec_sysvec_init(void *param)
 {
@@ -982,7 +986,7 @@ linux_exec_sysvec_init(void *param)
 	if (bootverbose)
 		printf("Linux i386 vDSO tsc_selector: %u\n", *ktsc_selector);
 }
-SYSINIT(elf_linux_exec_sysvec_init, SI_SUB_EXEC, SI_ORDER_ANY,
+SYSINIT(elf_linux_exec_sysvec_init, SI_SUB_EXEC + 1, SI_ORDER_ANY,
     linux_exec_sysvec_init, &elf_linux_sysvec);
 
 static void
@@ -1004,7 +1008,7 @@ linux_vdso_install(const void *param)
 
 	linux_vdso_reloc(linux_vdso_mapping, linux_vdso_base);
 }
-SYSINIT(elf_linux_vdso_init, SI_SUB_EXEC, SI_ORDER_FIRST,
+SYSINIT(elf_linux_vdso_init, SI_SUB_EXEC + 1, SI_ORDER_FIRST,
     linux_vdso_install, NULL);
 
 static void
diff --git a/sys/arm64/linux/linux_sysvec.c b/sys/arm64/linux/linux_sysvec.c
index 48d628d365d8..0e9800291e26 100644
--- a/sys/arm64/linux/linux_sysvec.c
+++ b/sys/arm64/linux/linux_sysvec.c
@@ -471,6 +471,10 @@ linux_on_exec_vmspace(struct proc *p, struct image_params *imgp)
 	return (error);
 }
 
+/*
+ * linux_vdso_install() and linux_exec_sysvec_init() must be called
+ * after exec_sysvec_init() which is SI_SUB_EXEC (SI_ORDER_ANY).
+ */
 static void
 linux_exec_sysvec_init(void *param)
 {
@@ -486,7 +490,7 @@ linux_exec_sysvec_init(void *param)
 	ktimekeep_base = (l_uintptr_t *)(linux_vdso_mapping + tkoff);
 	*ktimekeep_base = sv->sv_timekeep_base;
 }
-SYSINIT(elf_linux_exec_sysvec_init, SI_SUB_EXEC, SI_ORDER_ANY,
+SYSINIT(elf_linux_exec_sysvec_init, SI_SUB_EXEC + 1, SI_ORDER_ANY,
     linux_exec_sysvec_init, &elf_linux_sysvec);
 
 static void
@@ -508,7 +512,7 @@ linux_vdso_install(const void *param)
 
 	linux_vdso_reloc(linux_vdso_mapping, linux_vdso_base);
 }
-SYSINIT(elf_linux_vdso_init, SI_SUB_EXEC, SI_ORDER_FIRST,
+SYSINIT(elf_linux_vdso_init, SI_SUB_EXEC + 1, SI_ORDER_FIRST,
     linux_vdso_install, NULL);
 
 static void
diff --git a/sys/i386/linux/linux_sysvec.c b/sys/i386/linux/linux_sysvec.c
index b15854ff85a8..d312e7e9003e 100644
--- a/sys/i386/linux/linux_sysvec.c
+++ b/sys/i386/linux/linux_sysvec.c
@@ -912,6 +912,10 @@ linux_on_exec_vmspace(struct proc *p, struct image_params *imgp)
 	return (error);
 }
 
+/*
+ * linux_vdso_install() and linux_exec_sysvec_init() must be called
+ * after exec_sysvec_init() which is SI_SUB_EXEC (SI_ORDER_ANY).
+ */
 static void
 linux_exec_sysvec_init(void *param)
 {
@@ -933,7 +937,7 @@ linux_exec_sysvec_init(void *param)
 	if (bootverbose)
 		printf("Linux i386 vDSO tsc_selector: %u\n", *ktsc_selector);
 }
-SYSINIT(elf_linux_exec_sysvec_init, SI_SUB_EXEC, SI_ORDER_ANY,
+SYSINIT(elf_linux_exec_sysvec_init, SI_SUB_EXEC + 1, SI_ORDER_ANY,
     linux_exec_sysvec_init, &elf_linux_sysvec);
 
 static void
@@ -955,7 +959,7 @@ linux_vdso_install(const void *param)
 
 	linux_vdso_reloc(linux_vdso_mapping, linux_vdso_base);
 }
-SYSINIT(elf_linux_vdso_init, SI_SUB_EXEC, SI_ORDER_FIRST,
+SYSINIT(elf_linux_vdso_init, SI_SUB_EXEC + 1, SI_ORDER_FIRST,
     linux_vdso_install, NULL);
 
 static void
@@ -1166,3 +1170,8 @@ static moduledata_t linux_elf_mod = {
 
 DECLARE_MODULE_TIED(linuxelf, linux_elf_mod, SI_SUB_EXEC, SI_ORDER_ANY);
 FEATURE(linux, "Linux 32bit support");
+
+/*
+ * linux_vdso_install() and linux_exec_sysvec_init() must be called
+ * after exec_sysvec_init() which is SI_SUB_EXEC (SI_ORDER_ANY).
+ */