aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/kern_linker.c
Commit message (Collapse)AuthorAgeFilesLines
...
* Remove some NULL checks for M_WAITOK allocations.Edward Tomasz Napierala2016-03-291-2/+0
| | | | | | | | MFC after: 1 month Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=297391
* Create the MDT_PNP_INFO metadata record to communicate PNP info aboutWarner Losh2015-12-111-3/+3
| | | | | | | | | | modules. External agents may use this data to automatically load those modules. Differential Review: https://reviews.freebsd.org/D3461 Notes: svn path=/head/; revision=292077
* Export various helper variables describing the layout and size ofJohn Baldwin2015-11-121-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | certain kernel structures for use by debuggers. This mostly aids in examining cores from a kernel without debug symbols as a debugger can infer these values if debug symbols are available. One set of variables describes the layout of 'struct linker_file' to walk the list of loaded kernel modules. A second set of variables describes the layout of 'struct proc' and 'struct thread' to walk the list of processes in the kernel and the threads in each process. The 'pcb_size' variable is used to index into the stoppcbs[] array. The 'vm_maxuser_address' is used to distinguish kernel virtual addresses from user addresses. This doesn't have to be perfect, and 'vm_maxuser_address' is a cheap and simple way to differentiate kernel pointers from simple values like TIDs and PIDs. While here, annotate the fields in struct pcb used by kgdb on amd64 and i386 to note that their ABI should be preserved. Annotations for other platforms will be added in the future. Reviewed by: kib MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D3773 Notes: svn path=/head/; revision=290728
* sysctl: switch sysctllock to a sleepable rmlock, take 2Mateusz Guzik2015-09-151-4/+4
| | | | | | | | This restores r285125. Previous attempt was reverted due to a bug in rmlocks, which is fixed since r287833. Notes: svn path=/head/; revision=287835
* Revert r285125 until rmlocks get fixed.Mateusz Guzik2015-07-301-4/+4
| | | | | | | | | Right now there is a chance that sysctl unregister will cause reader to block on the sx lock associated with sysctl rmlock, in which case kernels with debug enabled will panic. Notes: svn path=/head/; revision=286094
* sysctl: switch sysctllock to a sleepable rmlockMateusz Guzik2015-07-041-4/+4
| | | | | | | The lock is almost never taken for writing. Notes: svn path=/head/; revision=285125
* Revert r284153, as I believe it breaks the dtrace sdt module. I willJohn Baldwin2015-06-081-31/+13
| | | | | | | fix the original issue a different way. Notes: svn path=/head/; revision=284160
* Add an internal "locked" variant of linker_file_lookup_set() and changeJohn Baldwin2015-06-081-13/+31
| | | | | | | | the public function to acquire the global linker lock directly. This permits linker_file_lookup_set() to be safely used from other modules. Notes: svn path=/head/; revision=284153
* Const poison in a few places to ensure we don't modify thingsWarner Losh2014-12-031-8/+8
| | | | | | | through the module data pointer. Notes: svn path=/head/; revision=275469
* The current limit of 100k for the linker hints file is getting a bitWarner Losh2014-11-291-1/+1
| | | | | | | | | | | crowded as we now are at about 70k. Bump the limit to 1MB instead which is still quite a reasonable limit and allows for future growth of this file and possible future expansion to additional data. MFC After: 2 weeks Notes: svn path=/head/; revision=275261
* Take the lock shared in linker_search_symbol_name.Mateusz Guzik2014-10-211-2/+2
| | | | | | | This helps sysctl kern.proc.stack. Notes: svn path=/head/; revision=273431
* Rename sysctl_lock and _unlock to sysctl_xlock and _xunlock.Mateusz Guzik2014-10-211-4/+4
| | | | Notes: svn path=/head/; revision=273400
* Fully support constructors for the purpose of code coverage analysis.Marcel Moolenaar2014-10-201-0/+2
| | | | | | | | | | | | | | | | | | | | This involves: 1. Have the loader pass the start and size of the .ctors section to the kernel in 2 new metadata elements. 2. Have the linker backends look for and record the start and size of the .ctors section in dynamically loaded modules. 3. Have the linker backends call the constructors as part of the final work of initializing preloaded or dynamically loaded modules. Note that LLVM appends the priority of the constructors to the name of the .ctors section. Not so when compiling with GCC. The code currently works for GCC and not for LLVM. Submitted by: Dmitry Mikulin <dmitrym@juniper.net> Obtained from: Juniper Networks, Inc. Notes: svn path=/head/; revision=273334
* Pull in r267961 and r267973 again. Fix for issues reported will follow.Hans Petter Selasky2014-06-281-3/+2
| | | | Notes: svn path=/head/; revision=267992
* Revert r267961, r267973:Glen Barber2014-06-271-2/+3
| | | | | | | | | | | | | These changes prevent sysctl(8) from returning proper output, such as: 1) no output from sysctl(8) 2) erroneously returning ENOMEM with tools like truss(1) or uname(1) truss: can not get etype: Cannot allocate memory Notes: svn path=/head/; revision=267985
* Extend the meaning of the CTLFLAG_TUN flag to automatically check ifHans Petter Selasky2014-06-271-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | there is an environment variable which shall initialize the SYSCTL during early boot. This works for all SYSCTL types both statically and dynamically created ones, except for the SYSCTL NODE type and SYSCTLs which belong to VNETs. A new flag, CTLFLAG_NOFETCH, has been added to be used in the case a tunable sysctl has a custom initialisation function allowing the sysctl to still be marked as a tunable. The kernel SYSCTL API is mostly the same, with a few exceptions for some special operations like iterating childrens of a static/extern SYSCTL node. This operation should probably be made into a factored out common macro, hence some device drivers use this. The reason for changing the SYSCTL API was the need for a SYSCTL parent OID pointer and not only the SYSCTL parent OID list pointer in order to quickly generate the sysctl path. The motivation behind this patch is to avoid parameter loading cludges inside the OFED driver subsystem. Instead of adding special code to the OFED driver subsystem to post-load tunables into dynamically created sysctls, we generalize this in the kernel. Other changes: - Corrected a possibly incorrect sysctl name from "hw.cbb.intr_mask" to "hw.pcic.intr_mask". - Removed redundant TUNABLE statements throughout the kernel. - Some minor code rewrites in connection to removing not needed TUNABLE statements. - Added a missing SYSCTL_DECL(). - Wrapped two very long lines. - Avoid malloc()/free() inside sysctl string handling, in case it is called to initialize a sysctl from a tunable, hence malloc()/free() is not ready when sysctls from the sysctl dataset are registered. - Bumped FreeBSD version to indicate SYSCTL API change. MFC after: 2 weeks Sponsored by: Mellanox Technologies Notes: svn path=/head/; revision=267961
* Use realloc(9) instead of doing the reallocation inline.Konstantin Belousov2014-04-051-8/+2
| | | | | | | | Submitted by: bde MFC after: 1 week Notes: svn path=/head/; revision=264173
* Use correct types for sizeof() in the calculations for the malloc(9) sizes [1].Konstantin Belousov2014-03-121-6/+3
| | | | | | | | | | While there, remove unneeded checks for failed allocations with M_WAITOK flag. Submitted by: Conrad Meyer <cemeyer@uw.edu> [1] MFC after: 1 week Notes: svn path=/head/; revision=263080
* Invoke the kld_* event handlers from linker_load_file() andMark Johnston2013-12-191-24/+14
| | | | | | | | | | | | | | | | | linker_unload_file() rather than kern_kldload() and kern_kldunload(). This ensures that the handlers are invoked for files that are loaded/unloaded automatically as dependencies. Previously, they were only invoked for files loaded by a user. As a side effect, the kld_load and kld_unload handlers are now invoked with the kernel linker lock exclusively held. Reported by: avg Reviewed by: jhb MFC after: 2 weeks Notes: svn path=/head/; revision=259587
* Rename the kld_unload event handler to kld_unload_try, and add a newMark Johnston2013-08-241-26/+13
| | | | | | | | | | | | | | | | | kld_unload event handler which gets invoked after a linker file has been successfully unloaded. The kld_unload and kld_load event handlers are now invoked with the shared linker lock held, while kld_unload_try is invoked with the lock exclusively held. Convert hwpmc(4) to use these event handlers instead of having kern_kldload() and kern_kldunload() invoke hwpmc(4) hooks whenever files are loaded or unloaded. This has no functional effect, but simplifes the linker code somewhat. Reviewed by: jhb Notes: svn path=/head/; revision=254813
* Set things up so that linker_file_lookup_set() is always called with theMark Johnston2013-08-241-12/+20
| | | | | | | | | | linker lock held. This makes it possible to call it from a kld event handler with the shared lock held. Reviewed by: jhb Notes: svn path=/head/; revision=254811
* Remove the kld lock macros and just use the sx(9) API. Add locking inMark Johnston2013-08-241-67/+62
| | | | | | | | | | linker_init_kernel_modules() and linker_preload() in order to remove most of the checks for !cold before asserting that the kld lock is held. These routines are invoked by SYSINIT(9), so there's no harm in them taking the kld lock. Notes: svn path=/head/; revision=254810
* Use strdup(9) instead of reimplementing it.Mark Johnston2013-08-161-14/+4
| | | | Notes: svn path=/head/; revision=254396
* Use kld_{load,unload} instead of mod_{load,unload} for the linker file loadMark Johnston2013-08-141-2/+2
| | | | | | | | | | and unload event handlers added in r254266. Reported by: jhb X-MFC with: r254266 Notes: svn path=/head/; revision=254309
* FreeBSD's DTrace implementation has a few problems with respect to handlingMark Johnston2013-08-131-5/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | probes declared in a kernel module when that module is unloaded. In particular, * Unloading a module with active SDT probes will cause a panic. [1] * A module's (FBT/SDT) probes aren't destroyed when the module is unloaded; trying to use them after the fact will generally cause a panic. This change fixes both problems by porting the DTrace module load/unload handlers from illumos and registering them with the corresponding EVENTHANDLER(9) handlers. This allows the DTrace framework to destroy all probes defined in a module when that module is unloaded, and to prevent a module unload from proceeding if some of its probes are active. The latter problem has already been fixed for FBT probes by checking lf->nenabled in kern_kldunload(), but moving the check into the DTrace framework generalizes it to all kernel providers and also fixes a race in the current implementation (since a probe may be activated between the check and the call to linker_file_unload()). Additionally, the SDT implementation has been reworked to define SDT providers/probes/argtypes in linker sets rather than using SYSINIT/SYSUNINIT to create and destroy SDT probes when a module is loaded or unloaded. This simplifies things quite a bit since it means that pretty much all of the SDT code can live in sdt.ko, and since it becomes easier to integrate SDT with the DTrace framework. Furthermore, this allows FreeBSD to be quite flexible in that SDT providers spanning multiple modules can be created on the fly when a module is loaded; at the moment it looks like illumos' SDT implementation requires all SDT probes to be statically defined in a single kernel table. PR: 166927, 166926, 166928 Reported by: davide [1] Reviewed by: avg, trociny (earlier version) MFC after: 1 month Notes: svn path=/head/; revision=254268
* Remove some unused fields from struct linker_file. They were added inMark Johnston2013-08-131-2/+0
| | | | | | | | | | r172862 for use by the DTrace SDT framework but don't seem to have ever been used. MFC after: 2 weeks Notes: svn path=/head/; revision=254267
* Add event handlers for module load and unload events. The load handlers areMark Johnston2013-08-131-2/+8
| | | | | | | | | | | | called after the module has been loaded, and the unload handlers are called before the module is unloaded. Moreover, the module unload handlers may return an error to prevent the unload from proceeding. Reviewed by: avg MFC after: 2 weeks Notes: svn path=/head/; revision=254266
* Remove the support for using non-mpsafe filesystem modules.Konstantin Belousov2012-10-221-9/+3
| | | | | | | | | | | | | | | In particular, do not lock Giant conditionally when calling into the filesystem module, remove the VFS_LOCK_GIANT() and related macros. Stop handling buffers belonging to non-mpsafe filesystems. The VFS_VERSION is bumped to indicate the interface change which does not result in the interface signatures changes. Conducted and reviewed by: attilio Tested by: pho Notes: svn path=/head/; revision=241896
* If a linker file contains at least one module, but all of the modulesJohn Baldwin2012-04-121-2/+13
| | | | | | | | | | | fail to load (the MOD_LOAD event fails) during a kldload(2), unload the linker file and fail the kldload(2) with ENOEXEC. Reported by: gcooper MFC after: 1 week Notes: svn path=/head/; revision=234186
* Correct debug message.Andrey V. Elsukov2012-03-221-1/+1
| | | | Notes: svn path=/head/; revision=233295
* Acquire modules lock before call module_getname() in the KLD_DEBUG case.Andrey V. Elsukov2012-03-211-0/+4
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=233276
* Add CTLFLAG_TUN to the sysctl definition and fix style.Andrey V. Elsukov2012-03-151-2/+2
| | | | | | | | Pointed by: Garrett Cooper MFC after: 2 weeks Notes: svn path=/head/; revision=232999
* Add debug.kld_debug loader tunable.Andrey V. Elsukov2012-03-151-0/+1
| | | | | | | MFC after: 2 weeks Notes: svn path=/head/; revision=232997
* Fix found places where uio_resid is truncated to int.Konstantin Belousov2012-02-211-2/+3
| | | | | | | | | | | | Add the sysctl debug.iosize_max_clamp, enabled by default. Setting the sysctl to zero allows to perform the SSIZE_MAX-sized i/o requests from the usermode. Discussed with: bde, das (previous versions) MFC after: 1 month Notes: svn path=/head/; revision=231949
* Revert r231923 for now. Further work is needed to make sure that theXin LI2012-02-201-1/+1
| | | | | | | behavior is consistent. Notes: svn path=/head/; revision=231931
* Use uprintf instead of printf for the reason why a kernel module can notXin LI2012-02-201-1/+1
| | | | | | | | | | be loaded. This way, the administrator can get response immediately from the shell session rather than relying on dmesg. MFC after: 1 month Notes: svn path=/head/; revision=231923
* Use strchr() and strrchr().Ed Schouten2012-01-021-3/+3
| | | | | | | | | | | It seems strchr() and strrchr() are used more often than index() and rindex(). Therefore, simply migrate all kernel code to use it. For the XFS code, remove an empty line to make the code identical to the code in the Linux kernel. Notes: svn path=/head/; revision=229272
* Add KLD_DEBUG option.Max Khon2011-11-061-0/+1
| | | | Notes: svn path=/head/; revision=227151
* In order to maximize the re-usability of kernel code in user space thisKip Macy2011-09-161-8/+8
| | | | | | | | | | | | | | | | patch modifies makesyscalls.sh to prefix all of the non-compatibility calls (e.g. not linux_, freebsd32_) with sys_ and updates the kernel entry points and all places in the code that use them. It also fixes an additional name space collision between the kernel function psignal and the libc function of the same name by renaming the kernel psignal kern_psignal(). By introducing this change now we will ease future MFCs that change syscalls. Reviewed by: rwatson Approved by: re (bz) Notes: svn path=/head/; revision=225617
* Don't leak kld_sx lock in kldunloadf().Gleb Smirnoff2011-07-311-1/+2
| | | | | | | Approved by: re (kib) Notes: svn path=/head/; revision=224546
* Fix a LOR between hwpmc and the kernel linker. When a system-wideRyan Stone2011-07-171-11/+24
| | | | | | | | | | | | | | | | | | | | | | | | | sampling mode PMC is allocated, hwpmc calls linker_hwpmc_list_objects() while already holding an exclusive lock on pmc-sx lock. list_objects() tries to acquire an exclusive lock on the kld_sx lock. When a KLD module is loaded or unloaded successfully, kern_kld(un)load calls into the pmc hook while already holding an exclusive lock on the kld_sx lock. Calling the pmc hook requires acquiring a shared lock on the pmc-sx lock. Fix this by only acquiring a shared lock on the kld_sx lock in linker_hwpmc_list_objects(), and also downgrading to a shared lock on the kld_sx lock in kern_kld(un)load before calling into the pmc hook. In kern_kldload this required moving some modifications of the linker_file_t to happen before calling into the pmc hook. This fixes the deadlock by ensuring that the hwpmc -> list_objects() case is always able to proceed. Without this patch, I was able to deadlock a multicore system within minutes by constantly loading and unloading an KLD module while I simultaneously started a sampling mode PMC in a loop. MFC after: 1 month Notes: svn path=/head/; revision=224156
* Provide compat32 shims for kldstat(2).Konstantin Belousov2011-03-301-23/+30
| | | | | | | | Requested and tested by: jpaetzel MFC after: 1 week Notes: svn path=/head/; revision=220158
* Specify a CTLTYPE_FOO so that a future sysctl(8) change does not needMatthew D Fleming2011-01-181-1/+1
| | | | | | | to rely on the format string. Notes: svn path=/head/; revision=217555
* Fix page fault that occurred when trying to initialize preloaded kernel module,Edward Tomasz Napierala2011-01-051-3/+11
| | | | | | | | | | | | | | | | | the dependency of which was preloaded, but failed to initialize. Previously, kernel dereferenced NULL pointer returned by modlist_lookup2(); now, when this happens, we unload the dependent module. Since the depended_files list is sorted in dependency order, this properly propagates, unloading modules that depend on failed ones. From the user point of view, this prevents the kernel from panicing when trying to boot kernel compiled without KDTRACE_HOOKS with dtraceall_load="YES" in /boot/loader.conf. Reviewed by: kib Notes: svn path=/head/; revision=216988
* kdb_backtrace: use stack_print_ddb instead of stack_printAndriy Gapon2010-09-221-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a followup to r212964. stack_print call chain obtains linker sx lock and thus potentially may lead to a deadlock depending on a kind of a panic. stack_print_ddb doesn't acquire any locks and it doesn't use any facilities of ddb backend. Using stack_print_ddb outside of DDB ifdef required taking a number of helper functions from under it as well. It is a good idea to rename linker_ddb_* and stack_*_ddb functions to have 'unlocked' component in their name instead of 'ddb', because those functions do not use any DDB services, but instead they provide unlocked access to linker symbol information. The latter was previously needed only for DDB, hence the 'ddb' name component. Alternative is to ditch unlocked versions altogether after implementing proper panic handling: 1. stop other cpus upon a panic 2. make all non-spinlock lock operations (mutex, sx, rwlock) be a no-op when panicstr != NULL Suggested by: mdf Discussed with: attilio MFC after: 2 weeks Notes: svn path=/head/; revision=212994
* - Unbreak build with KLD_DEBUG definedOleksandr Tymoshenko2009-11-171-1/+6
| | | | | | | | - Add debug.kld_debug sysctl to control KLD debugging level - Print information about KLD dependencies with debug enabled Notes: svn path=/head/; revision=199457
* Revert previous commit and add myself to the list of people who shouldPoul-Henning Kamp2009-09-081-1/+0
| | | | | | | know better than to commit with a cat in the area. Notes: svn path=/head/; revision=196970
* Add necessary include.Poul-Henning Kamp2009-09-081-0/+1
| | | | Notes: svn path=/head/; revision=196969
* Merge the remainder of kern_vimage.c and vimage.h into vnet.c andRobert Watson2009-08-011-1/+2
| | | | | | | | | | | | | vnet.h, we now use jails (rather than vimages) as the abstraction for virtualization management, and what remained was specific to virtual network stacks. Minor cleanups are done in the process, and comments updated to reflect these changes. Reviewed by: bz Approved by: re (vimage blanket) Notes: svn path=/head/; revision=196019
* Improve the printf message when a module failed to load. This gives theRui Paulo2009-07-211-2/+2
| | | | | | | | | | user some clue about the possibility of a __FreeBSD_version mismatch. Discussed with: rwatson, jhb Approved by: re (kib) Notes: svn path=/head/; revision=195803