diff --git a/sys/compat/linuxkpi/common/include/linux/module.h b/sys/compat/linuxkpi/common/include/linux/module.h --- a/sys/compat/linuxkpi/common/include/linux/module.h +++ b/sys/compat/linuxkpi/common/include/linux/module.h @@ -51,7 +51,23 @@ #define MODULE_SUPPORTED_DEVICE(name) #define MODULE_IMPORT_NS(_name) -#define THIS_MODULE ((struct module *)0) +/* + * THIS_MODULE is used to differentiate modules on Linux. We currently + * completely stub out any Linux struct module usage, but THIS_MODULE is still + * used to populate the "owner" fields of various drivers. Even though we + * don't actually dereference these "owner" fields they are still used by + * drivers to check if devices/dmabufs/etc come from different modules. For + * example, during DRM GEM import some drivers check if the dmabuf's owner + * matches the dev's owner. If they match because they are both NULL drivers + * may incorrectly think two resources come from the same module. + * + * To handle this we specify an undefined symbol __lkpi_this_module, which + * will get special treatment from the linker when resolving. This will + * populate the usages of __lkpi_this_module with the linker_file_t of the + * module. + */ +extern struct linker_file *__lkpi_this_module; +#define THIS_MODULE ((struct module *)&__lkpi_this_module) #define __MODULE_STRING(x) __stringify(x) diff --git a/sys/kern/kern_linker.c b/sys/kern/kern_linker.c --- a/sys/kern/kern_linker.c +++ b/sys/kern/kern_linker.c @@ -906,6 +906,14 @@ KLD_DPF(SYM, ("linker_file_lookup_symbol: file=%p, name=%s, deps=%d\n", file, name, deps)); + /* + * Treat the __lkpi_this_module as a special symbol. This is a global that + * linuxkpi uses to populate the THIS_MODULE value. In this case we can + * simply return the linker_file_t. + */ + if (strcmp(name, "__lkpi_this_module") == 0) + return ((caddr_t)file); + if (LINKER_LOOKUP_SYMBOL(file, name, &sym) == 0) { LINKER_SYMBOL_VALUES(file, sym, &symval); if (symval.value == 0)