Page MenuHomeFreeBSD

kern linker: Do not invoke event handlers for partially linked file
Needs ReviewPublic

Authored by zlei on Tue, Apr 2, 2:25 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Apr 28, 12:12 PM
Unknown Object (File)
Fri, Apr 26, 4:39 AM
Unknown Object (File)
Wed, Apr 17, 4:09 PM
Unknown Object (File)
Wed, Apr 17, 4:04 PM
Unknown Object (File)
Tue, Apr 16, 1:37 PM
Unknown Object (File)
Sat, Apr 6, 5:04 PM
Unknown Object (File)
Thu, Apr 4, 8:37 PM
Unknown Object (File)
Tue, Apr 2, 11:01 PM
Subscribers

Details

Reviewers
markj
jhb
dfr
olce
Summary

The kernel linkers would call linker_file_unload() to unload partially
linked file. At this moment event handlers kld_load have not been
invoked yet so it makes no senses to invoke kld_unload_try and kld_unload
event handlers.

PR: 274375
Fixes: 8f7254629ff1 Invoke the kld_* event handlers from linker_load_file() ...
MFC after: 2 weeks

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

zlei requested review of this revision.Tue, Apr 2, 2:25 PM

The only in-tree consumers of kld_unload_try and kld_unload even handlers are sdt and dtrace. Hopefully these even handlers are not abused by out-tree consumers.

Is it possible instead to reuse LINKER_FILE_LINKED, by setting this flag later in linker_load_file() (after the if (modules && TAILQ_EMPTY(&lf->modules))), and testing for it? This would also improve the behavior of linker_find_file_by_id() by preventing it from reporting a loaded module that is immediately unloaded by the just-mentioned if.

To make that work, you have to copy the code unregistering the sysctls into linker_load_file() (or, perhaps better, factorize into a small inline function called from it and linker_file_unload()).

Another option could be refactor linker_file_unload() into two functions. One for normal unload and another is for abnormal ones such as unloading partially linked file.
Almost all abnormal unload requires the flag LINKER_UNLOAD_FORCE and at that moment the reference count of file should be right one. The logic will be much clear.

Another option could be refactor linker_file_unload() into two functions. One for normal unload and another is for abnormal ones such as unloading partially linked file.
Almost all abnormal unload requires the flag LINKER_UNLOAD_FORCE and at that moment the reference count of file should be right one. The logic will be much clear.

But then, how do you plan to know when to call linker_file_unregister_sysctls() and linker_file_sysuninit()? It looks like the first one is not really a problem, but the second seems to be (I have not checked more in depth).

linker_unload_file() already takes a flag argument to be able to distinguish normal from abnormal unloading. So I don't think I understand what you're up to here.