git: d70230783ae2 - main - vmm: Postpone vmm module initialization to after SI_SUB_DEVFS

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Thu, 07 Nov 2024 20:38:55 UTC
The branch main has been updated by markj:

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

commit d70230783ae27594a77560582093dd86426d3360
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2024-11-07 20:07:39 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-11-07 20:38:38 +0000

    vmm: Postpone vmm module initialization to after SI_SUB_DEVFS
    
    vmmops_modinit() needs to create a device file, and this must happen
    after SI_SUB_DEVFS.  On non-EARLY_AP_STARTUP platforms (i.e., !x86) this
    happens already by accident, but we shouldn't rely on it.
    
    On riscv, remove the current SI_SUB_SMP ordering since that was copied
    from arm64 and isn't needed.  In particular, riscv's vmmops_modinit()
    does not call smp_rendezvous().
    
    Reported by:    Oleksandr Kryvulia <shuriku@shurik.kiev.ua>
    Fixes:  a97f683fe3c4 ("vmm: Add a device file interface for creating and destroying VMs")
---
 sys/amd64/vmm/vmm.c | 3 ++-
 sys/arm64/vmm/vmm.c | 3 ++-
 sys/riscv/vmm/vmm.c | 5 ++---
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/sys/amd64/vmm/vmm.c b/sys/amd64/vmm/vmm.c
index 77e0adda86f5..9569f8ace909 100644
--- a/sys/amd64/vmm/vmm.c
+++ b/sys/amd64/vmm/vmm.c
@@ -513,8 +513,9 @@ static moduledata_t vmm_kmod = {
  *
  * - VT-x initialization requires smp_rendezvous() and therefore must happen
  *   after SMP is fully functional (after SI_SUB_SMP).
+ * - vmm device initialization requires an initialized devfs.
  */
-DECLARE_MODULE(vmm, vmm_kmod, SI_SUB_SMP + 1, SI_ORDER_ANY);
+DECLARE_MODULE(vmm, vmm_kmod, MAX(SI_SUB_SMP, SI_SUB_DEVFS) + 1, SI_ORDER_ANY);
 MODULE_VERSION(vmm, 1);
 
 static void
diff --git a/sys/arm64/vmm/vmm.c b/sys/arm64/vmm/vmm.c
index 2f4f3a2b59ea..808df5e599ac 100644
--- a/sys/arm64/vmm/vmm.c
+++ b/sys/arm64/vmm/vmm.c
@@ -396,8 +396,9 @@ static moduledata_t vmm_kmod = {
  *
  * - HYP initialization requires smp_rendezvous() and therefore must happen
  *   after SMP is fully functional (after SI_SUB_SMP).
+ * - vmm device initialization requires an initialized devfs.
  */
-DECLARE_MODULE(vmm, vmm_kmod, SI_SUB_SMP + 1, SI_ORDER_ANY);
+DECLARE_MODULE(vmm, vmm_kmod, MAX(SI_SUB_SMP, SI_SUB_DEVFS) + 1, SI_ORDER_ANY);
 MODULE_VERSION(vmm, 1);
 
 static void
diff --git a/sys/riscv/vmm/vmm.c b/sys/riscv/vmm/vmm.c
index 1c0290ace570..f8be363b6170 100644
--- a/sys/riscv/vmm/vmm.c
+++ b/sys/riscv/vmm/vmm.c
@@ -287,10 +287,9 @@ static moduledata_t vmm_kmod = {
 /*
  * vmm initialization has the following dependencies:
  *
- * - HYP initialization requires smp_rendezvous() and therefore must happen
- *   after SMP is fully functional (after SI_SUB_SMP).
+ * - vmm device initialization requires an initialized devfs.
  */
-DECLARE_MODULE(vmm, vmm_kmod, SI_SUB_SMP + 1, SI_ORDER_ANY);
+DECLARE_MODULE(vmm, vmm_kmod, SI_SUB_DEVFS + 1, SI_ORDER_ANY);
 MODULE_VERSION(vmm, 1);
 
 static void