From cef0ea8f726ef2faa030a2b2e1edd7b0f4638e04 Mon Sep 17 00:00:00 2001 From: kevans Date: Thu, 22 Mar 2018 18:24:00 +0000 Subject: [PATCH] Re-work efidev ordering to fix efirt preloaded by loader on amd64 On amd64, efi_enter calls fpu_kern_enter(). This may not be called until fpuinitstate has been invoked, resulting in a kernel panic with efirt_load="YES" in loader.conf(5). Move fpuinitstate a little earlier in SI_SUB_DRIVERS so that we can squeeze efirt between it and efirtc at SI_SUB_DRIVERS, SI_ORDER_ANY. efidev must be after efirt and doesn't really need to be at SI_SUB_DEVFS, so drop it at SI_SUB_DRIVER, SI_ORDER_ANY. The not immediately obvious dependency of fpuinitstate by efirt has been noted in both places. Discussed with: kib, andrew Reported by: Jakob Alvermark X-MFC-With: r330868 --- sys/amd64/amd64/fpu.c | 3 ++- sys/dev/efidev/efidev.c | 2 +- sys/dev/efidev/efirt.c | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/sys/amd64/amd64/fpu.c b/sys/amd64/amd64/fpu.c index 39367fa6ffb5..c3b254ef5ab9 100644 --- a/sys/amd64/amd64/fpu.c +++ b/sys/amd64/amd64/fpu.c @@ -366,7 +366,8 @@ fpuinitstate(void *arg __unused) start_emulating(); intr_restore(saveintr); } -SYSINIT(fpuinitstate, SI_SUB_DRIVERS, SI_ORDER_ANY, fpuinitstate, NULL); +/* EFIRT needs this to be initialized before we can enter our EFI environment */ +SYSINIT(fpuinitstate, SI_SUB_DRIVERS, SI_ORDER_FIRST, fpuinitstate, NULL); /* * Free coprocessor (if we have it). diff --git a/sys/dev/efidev/efidev.c b/sys/dev/efidev/efidev.c index 587199cbef94..01b6c379b0c0 100644 --- a/sys/dev/efidev/efidev.c +++ b/sys/dev/efidev/efidev.c @@ -216,6 +216,6 @@ static moduledata_t efidev_moddata = { .priv = NULL, }; -DECLARE_MODULE(efidev, efidev_moddata, SI_SUB_DEVFS, SI_ORDER_ANY); +DECLARE_MODULE(efidev, efidev_moddata, SI_SUB_DRIVERS, SI_ORDER_ANY); MODULE_VERSION(efidev, 1); MODULE_DEPEND(efidev, efirt, 1, 1, 1); diff --git a/sys/dev/efidev/efirt.c b/sys/dev/efidev/efirt.c index a1ed4d214e43..4015444ef17c 100644 --- a/sys/dev/efidev/efirt.c +++ b/sys/dev/efidev/efirt.c @@ -450,5 +450,6 @@ static moduledata_t efirt_moddata = { .evhand = efirt_modevents, .priv = NULL, }; -DECLARE_MODULE(efirt, efirt_moddata, SI_SUB_VM_CONF, SI_ORDER_ANY); +/* After fpuinitstate, before efidev */ +DECLARE_MODULE(efirt, efirt_moddata, SI_SUB_DRIVERS, SI_ORDER_SECOND); MODULE_VERSION(efirt, 1);