Bug 274388

Summary: Several modules declare dependency on non-existent 'g_flashmap' kmod
Product: Base System Reporter: Colin Gordon <csgordon>
Component: kernAssignee: freebsd-bugs (Nobody) <bugs>
Status: Open ---    
Severity: Affects Only Me CC: freebsd, grahamperrin, markj
Priority: ---    
Version: CURRENT   
Hardware: riscv   
OS: Any   
URL: https://github.com/csgordon/freebsd-starfive2/commit/95e24f536ddd4bde5f3b441c5e3a45a5a0acc49d

Description Colin Gordon 2023-10-10 00:32:41 UTC
While I encountered this working on support for a RISC-V board, the specific code in question is platform-independent.

The mmcsd code (sys/dev/mmc/mmcsd.c) declares a module dependency on a module called g_flashmap. However, this module doesn't exist. So if mmcsd is built as a module, it cannot be loaded, you get an error message about this non-existent module not being found.

g_flashmap is actually a prefix used internally in the geom_flashmap code. Turns out that also affects fdt_slicer as well, but the fix is just 4 fixes to refer to the actual module: https://github.com/csgordon/freebsd-starfive2/commit/95e24f536ddd4bde5f3b441c5e3a45a5a0acc49d
Comment 1 Graham Perrin 2023-10-10 06:50:14 UTC
Sorry, 

> platform-independent.
Comment 2 Mina Galić freebsd_triage 2023-10-10 07:46:58 UTC
how did the code in geom_flashmap even compile?
Comment 3 Colin Gordon 2023-10-10 11:48:12 UTC
I'm relatively new to working in the FreeBSD kernel, so it's quite possible there's a subtlety in missing or some kind of module validation check in not aware of that has broken. But the C code itself doesn't care about the dependency declaration, so geom_flashmap itself is fine, but does declare a module name that's not tied to the *filename* of the final kld, and kld loading assumes the declared dependency name matches the filename, which is what fails. That's why my local fix is to change the module declarations to match the filename.

On amd64 it appears that both geom_flashmap and mmcsd are linked directly into the kernel, so the kld loading code doesn't encounter the name mismatch.
Comment 4 Mark Johnston freebsd_committer freebsd_triage 2023-10-12 13:46:23 UTC
I suspect the problem is that you don't have a /boot/kernel/linker.hints file.  So when the kernel loads a module which depends on g_flashmap, it doesn't know that that corresponds to geom_flashmap.ko.  Your patch changes the module name to geom_flashmap, and linker_hints_lookup() will always try to load <module name>.ko, so it works.  Note that in FreeBSD, kernel modules and linker files (.ko files) are not exactly the same.  A linker file may contain multiple modules.

Assuming my guess is right, your patch just works around one specific consequence of not having a linker.hints.  OTOH, almost all of the GEOM modules are named geom_*, so maybe the patch should be committed anyway...