git: 662497d5a741 - main - SYSINIT: add explicit SI_ORDER_LAST
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 11 Aug 2026 14:40:59 UTC
The branch main has been updated by glebius:
URL: https://cgit.FreeBSD.org/src/commit/?id=662497d5a7415f8779b7be03e39f66eb8419174d
commit 662497d5a7415f8779b7be03e39f66eb8419174d
Author: Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2026-08-11 14:39:30 +0000
Commit: Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2026-08-11 14:39:30 +0000
SYSINIT: add explicit SI_ORDER_LAST
Working on cleansing use of (SI_SUB_FOO + 1) construct through the kernel
I found a repeating pattern. Often a developer adds a module that depends
on certain subsystem to be fully instantiated and they want to put their
module SYSINIT right at the end of the SI_SUB_FOO. Such module usually
expects that nothing else within this subsystem shall depend on the
module.
The problem with SI_ORDER_ANY which practically was "the last" until this
change is that it is used very widely and people treat it literally as
"any", well, because this is what the name says. This lead to many parts
that could have dependencies later to be added as SI_ORDER_ANY.
So, our developer with the new subsystem that depends on SI_SUB_FOO has
three options:
1) Use SI_ORDER_ANY, but grep around ther kernel for other SI_SUB_FOO
entries to make sure that no dependencies are set to SI_ORDER_ANY. And in
case they are, shift them up and recheck if dependencies of those
dependencies are met.
2) Take next subsystem in sysinit list. However, the next one can be
SI_SUB_BAR, that is completely irrelevant from SI_SUB_FOO, and our
developer doesn't want to put his module's SYSINIT into SI_SUB_BAR, cause
it is ugly.
3) Use the (SI_SUB_FOO + 1) construct that violates -Werror=assign-enum.
The SI_ORDER_LAST solves this hard choice. If you know that nothing is
going to depend on your module within SI_SUB_FOO, but you depend on
SI_SUB_FOO, just use SI_ORDER_LAST.
Reviewed by: markj, emaste
Differential Revision: https://reviews.freebsd.org/D58709
---
sys/amd64/amd64/pmap.c | 4 ++--
sys/compat/linuxkpi/common/src/linux_current.c | 6 +++---
sys/dev/random/fenestrasX/fx_brng.c | 8 +-------
sys/geom/eli/g_eli.c | 2 +-
sys/kern/kern_environment.c | 2 +-
sys/kern/kern_umtx.c | 2 +-
sys/kern/subr_hints.c | 2 +-
sys/net/debugnet.c | 2 +-
sys/netinet/tcp_ratelimit.c | 2 +-
sys/sys/kernel.h | 3 ++-
sys/x86/x86/ucode.c | 2 +-
11 files changed, 15 insertions(+), 20 deletions(-)
diff --git a/sys/amd64/amd64/pmap.c b/sys/amd64/amd64/pmap.c
index b37700a53aec..9cf1c77f5a9a 100644
--- a/sys/amd64/amd64/pmap.c
+++ b/sys/amd64/amd64/pmap.c
@@ -1154,7 +1154,7 @@ pmap_delayed_invl_callout_init(void *arg __unused)
callout_init(&pmap_invl_callout, 1);
pmap_invl_callout_inited = true;
}
-SYSINIT(pmap_di_callout, SI_SUB_CPU + 1, SI_ORDER_ANY,
+SYSINIT(pmap_di_callout, SI_SUB_CPU, SI_ORDER_LAST,
pmap_delayed_invl_callout_init, NULL);
/*
@@ -11186,7 +11186,7 @@ pmap_cpu_init(void *arg __unused)
CPU_COPY(&all_cpus, &kernel_pmap->pm_active);
pmap_pti_init();
}
-SYSINIT(pmap_cpu, SI_SUB_CPU + 1, SI_ORDER_ANY, pmap_cpu_init, NULL);
+SYSINIT(pmap_cpu, SI_SUB_CPU, SI_ORDER_LAST, pmap_cpu_init, NULL);
static pdp_entry_t *
pmap_pti_pdpe(vm_offset_t va)
diff --git a/sys/compat/linuxkpi/common/src/linux_current.c b/sys/compat/linuxkpi/common/src/linux_current.c
index 3bc5d31d211a..b7ee4759ccbd 100644
--- a/sys/compat/linuxkpi/common/src/linux_current.c
+++ b/sys/compat/linuxkpi/common/src/linux_current.c
@@ -299,8 +299,8 @@ linux_current_init(void *arg __unused)
linuxkpi_thread_dtor, NULL, EVENTHANDLER_PRI_ANY);
lkpi_alloc_current = linux_alloc_current;
}
-SYSINIT(linux_current, SI_SUB_EVENTHANDLER + 1, SI_ORDER_SECOND,
- linux_current_init, NULL);
+SYSINIT(linux_current, SI_SUB_EVENTHANDLER, SI_ORDER_LAST, linux_current_init,
+ NULL);
static void
linux_current_uninit(void *arg __unused)
@@ -333,5 +333,5 @@ linux_current_uninit(void *arg __unused)
uma_zdestroy(linux_current_zone);
uma_zdestroy(linux_mm_zone);
}
-SYSUNINIT(linux_current, SI_SUB_EVENTHANDLER + 1, SI_ORDER_SECOND,
+SYSUNINIT(linux_current, SI_SUB_EVENTHANDLER, SI_ORDER_LAST,
linux_current_uninit, NULL);
diff --git a/sys/dev/random/fenestrasX/fx_brng.c b/sys/dev/random/fenestrasX/fx_brng.c
index eea63533c572..f996c6b14071 100644
--- a/sys/dev/random/fenestrasX/fx_brng.c
+++ b/sys/dev/random/fenestrasX/fx_brng.c
@@ -134,12 +134,6 @@ fxrng_brng_reseed(const void *entr, size_t sz)
FXRNG_BRNG_UNLOCK(rng);
}
-/*
- * Sysentvec and VDSO are initialized much later than SI_SUB_RANDOM. When
- * they're online, go ahead and push an initial root seed version.
- * INIT_SYSENTVEC runs at SI_SUB_EXEC:SI_ORDER_ANY, and SI_ORDER_ANY is the
- * maximum value, so we must run at SI_SUB_EXEC+1.
- */
static void
fxrng_vdso_sysinit(void *dummy __unused)
{
@@ -147,7 +141,7 @@ fxrng_vdso_sysinit(void *dummy __unused)
fxrng_push_seed_generation(fxrng_root.brng_generation);
FXRNG_BRNG_UNLOCK(&fxrng_root);
}
-SYSINIT(fxrng_vdso, SI_SUB_EXEC + 1, SI_ORDER_ANY, fxrng_vdso_sysinit, NULL);
+SYSINIT(fxrng_vdso, SI_SUB_EXEC, SI_ORDER_LAST, fxrng_vdso_sysinit, NULL);
/*
* Grab some bytes off an initialized, current generation RNG.
diff --git a/sys/geom/eli/g_eli.c b/sys/geom/eli/g_eli.c
index 6b763496baf5..622aa87d4e81 100644
--- a/sys/geom/eli/g_eli.c
+++ b/sys/geom/eli/g_eli.c
@@ -165,7 +165,7 @@ fetch_loader_passphrase(void * dummy)
kern_unsetenv("kern.geom.eli.passphrase");
}
}
-SYSINIT(geli_fetch_loader_passphrase, SI_SUB_KMEM + 1, SI_ORDER_ANY,
+SYSINIT(geli_fetch_loader_passphrase, SI_SUB_KMEM, SI_ORDER_LAST,
fetch_loader_passphrase, NULL);
static void
diff --git a/sys/kern/kern_environment.c b/sys/kern/kern_environment.c
index acbb94067457..bf459a38107a 100644
--- a/sys/kern/kern_environment.c
+++ b/sys/kern/kern_environment.c
@@ -511,7 +511,7 @@ init_dynamic_kenv(void *data __unused)
mtx_init(&kenv_lock, "kernel environment", NULL, MTX_DEF);
dynamic_kenv = true;
}
-SYSINIT(kenv, SI_SUB_KMEM + 1, SI_ORDER_FIRST, init_dynamic_kenv, NULL);
+SYSINIT(kenv, SI_SUB_KMEM, SI_ORDER_LAST, init_dynamic_kenv, NULL);
void
freeenv(char *env)
diff --git a/sys/kern/kern_umtx.c b/sys/kern/kern_umtx.c
index 4f6e2b339ba6..69ea90ce9972 100644
--- a/sys/kern/kern_umtx.c
+++ b/sys/kern/kern_umtx.c
@@ -180,7 +180,7 @@ static void umtxq_hash(struct umtx_key *key);
static int do_unlock_pp(struct thread *td, struct umutex *m, uint32_t flags,
bool rb);
static void umtx_thread_cleanup(struct thread *td);
-SYSINIT(umtx, SI_SUB_EVENTHANDLER+1, SI_ORDER_MIDDLE, umtxq_sysinit, NULL);
+SYSINIT(umtx, SI_SUB_EVENTHANDLER, SI_ORDER_LAST, umtxq_sysinit, NULL);
#define umtxq_signal(key, nwake) umtxq_signal_queue((key), (nwake), UMTX_SHARED_QUEUE)
diff --git a/sys/kern/subr_hints.c b/sys/kern/subr_hints.c
index 5691921dd028..e2577aa9a9b2 100644
--- a/sys/kern/subr_hints.c
+++ b/sys/kern/subr_hints.c
@@ -88,7 +88,7 @@ static_hints_to_env(void *data __unused)
}
/* Any time after dynamic env is setup */
-SYSINIT(hintenv, SI_SUB_KMEM + 1, SI_ORDER_SECOND, static_hints_to_env, NULL);
+SYSINIT(hintenv, SI_SUB_KMEM, SI_ORDER_LAST, static_hints_to_env, NULL);
/*
* Checks the environment to see if we even have any hints. If it has no hints,
diff --git a/sys/net/debugnet.c b/sys/net/debugnet.c
index 32a91256f51d..178aefafc6b3 100644
--- a/sys/net/debugnet.c
+++ b/sys/net/debugnet.c
@@ -917,7 +917,7 @@ dn_evh_init(void *ctx __unused)
dn_attach_cookie = EVENTHANDLER_REGISTER(ifnet_link_event,
dn_ifnet_event, NULL, EVENTHANDLER_PRI_ANY);
}
-SYSINIT(dn_evh_init, SI_SUB_EVENTHANDLER + 1, SI_ORDER_ANY, dn_evh_init, NULL);
+SYSINIT(dn_evh_init, SI_SUB_EVENTHANDLER, SI_ORDER_LAST, dn_evh_init, NULL);
/*
* DDB parsing helpers for debugnet(4) consumers.
diff --git a/sys/netinet/tcp_ratelimit.c b/sys/netinet/tcp_ratelimit.c
index 0c115066167c..9f8d9bd2cb47 100644
--- a/sys/netinet/tcp_ratelimit.c
+++ b/sys/netinet/tcp_ratelimit.c
@@ -1790,5 +1790,5 @@ tcp_rs_init(void *st __unused)
printf("TCP_ratelimit: Is now initialized\n");
}
-SYSINIT(tcp_rl_init, SI_SUB_SMP + 1, SI_ORDER_ANY, tcp_rs_init, NULL);
+SYSINIT(tcp_rl_init, SI_SUB_SMP, SI_ORDER_LAST, tcp_rs_init, NULL);
#endif
diff --git a/sys/sys/kernel.h b/sys/sys/kernel.h
index da502f8ba4b4..139a570c7ac6 100644
--- a/sys/sys/kernel.h
+++ b/sys/sys/kernel.h
@@ -194,7 +194,8 @@ enum sysinit_elem_order {
SI_ORDER_SEVENTH = 0x0000006, /* seventh */
SI_ORDER_EIGHTH = 0x0000007, /* eighth */
SI_ORDER_MIDDLE = 0x1000000, /* somewhere in the middle */
- SI_ORDER_ANY = 0xfffffff /* last */
+ SI_ORDER_ANY = 0xf000000, /* default */
+ SI_ORDER_LAST = 0xfffffff /* last */
};
/*
diff --git a/sys/x86/x86/ucode.c b/sys/x86/x86/ucode.c
index 8ee0c2978638..b6861abfb434 100644
--- a/sys/x86/x86/ucode.c
+++ b/sys/x86/x86/ucode.c
@@ -360,7 +360,7 @@ restart:
goto restart;
}
}
-SYSINIT(ucode_release, SI_SUB_SMP + 1, SI_ORDER_ANY, ucode_release, NULL);
+SYSINIT(ucode_release, SI_SUB_SMP, SI_ORDER_LAST, ucode_release, NULL);
void
ucode_load_ap(int cpu)