summaryrefslogtreecommitdiffstats
path: root/sys/kern
Commit message (Collapse)AuthorAgeFilesLines
* Fix page fault that occurred when trying to initialize preloaded kernel module,trasz2011-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
* kproc_exit() is already marked __dead2 so a NOTREACHED comment here isn'tjhb2011-01-041-1/+0
| | | | | | needed for lint. Submitted by: bde
* Finish r210923, 210926. Mark some devices as eternal.kib2011-01-046-10/+15
| | | | MFC after: 2 weeks
* Small whitespace nits and add a comment explaining why kthread_exit() canjhb2011-01-031-3/+6
| | | | call kproc_exit() that was lost earlier.
* Finishing touches to fork1() - ANSIfy missed function definition, style(9)trasz2011-01-021-27/+20
| | | | | fixes, removal of few comments that didn't really make sense and addition of fork_findpid() locking requirements.
* Mfp4 CH177924:bz2010-12-311-1/+8
| | | | | | | | | | | | Add and export constants of array sizes of jail parameters as compiled into the kernel. This is the least intrusive way to allow kvm to read the (sparse) arrays independent of the options the kernel was compiled with. Reviewed by: jhb (originally) MFC after: 1 week Sponsored by: The FreeBSD Foundation Sponsored by: CK Software GmbH
* Remove OBJ_CLEANING flag. The vfs_setdirty_locked_object() is the onlykib2010-12-291-1/+1
| | | | | | | | | | | | | consumer of the flag, and it used the flag because OBJ_MIGHTBEDIRTY was cleared early in vm_object_page_clean, before the cleaning pass was done. This is no longer true after r216799. Moreover, since OBJ_CLEANING is a flag, and not the counter, it could be reset too prematurely when parallel vm_object_page_clean() are performed. Reviewed by: alc (as a part of the bigger patch) MFC after: 1 month (after r216799 is merged)
* Fix several callout migration races:attilio2010-12-291-23/+119
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Problem1: Hypothesis: thread1 is doing a callout_reset_on(), within his callout handler, willing to implicitly or explicitly migrate the callout. thread2 is draining the callout. Thesys: * thread1 calls callout_lock() and locks the old callout cpu * thread1 performs the checks in the first path of the callout_reset_on() * thread1 hits this codepiece: /* * If the lock must migrate we have to check the state again as * we can't hold both the new and old locks simultaneously. */ if (c->c_cpu != cpu) { c->c_cpu = cpu; CC_UNLOCK(cc); goto retry; } which means it will drop the lock and 'retry' * thread2 will callout_lock() and locks the new callout cpu. thread1 spins on the new lock and will not keep going for the moment. * thread2 checks that the callout is not pending (as callout is currently running) and that it is not on cc->cc_curr (because cc now refers to the new callout and the callout is running on the old callout cpu) thus it thinks it is done and returns. * thread1 will now acquire the lock and then adds the callout to the new callout cpu queue That seems an obvious race as callout_stop() falsely reports the callout stopped or worse, callout_drain() falsely returns while the callout is still in use. - Solution1: Fixing this problem would require, in general, to lock both callout cpus at once while switching the c_cpu field and avoid cyclic deadlocks between callout cpus locks. The concept of CPUBLOCK is then introduced (working more or less like the blocked_lock for thread_lock() function) meaning: "in callout_lock(), spin until the c->c_cpu is not different from CPUBLOCK". That way the "original" callout cpu, referred to the above mentioned code snippet, will remain blocked until the lock handover is over critical path will remain covered. - Problem2: Having the callout currently executed on a specific callout cpu and contemporary pending on another callout cpu (as it can happen with current code) breaks, at least, the assumption callout_drain() returns just once the callout cannot be referenced anymore. - Solution2: Callout migration is deferred if the current callout is already under execution. The best place to do that is in softclock() and new members are added to the callout cpu structure in order to specify a pending migration is requested. That is necessary because the callout cannot be trusted (not freed) the 100% of times after the execution of the callout handler. CPUBLOCK will prevent, in the "deferred migration" case, that the callout gets freed in this case, stopping any callout_stop() and callout_drain() possible activity until the migration is actually performed. - Problem3: There is a further race in callout_drain(). In order to avoid a race between sleepqueue lock and callout cpu spinlock, in _callout_stop_safe(), the callout cpu lock is dropped, the sleepqueue lock is acquired and a new callout cpu lookup is performed. Note that the channel used for locking the sleepqueue is obtained from the "current" callout cpu (&cc->cc_waiting). If the callout migrated in the meanwhile, callout_drain() will end up using the wrong wchan for the sleepqueue (the locked one will be the older, while the new one will not really be locked) leading to a lock leak and a race access to sleepqueue. - Solution3: It is enough to check if a migration happened between the operation of acquiring the sleepqueue lock and the new callout cpu lock and eventually unwind all those and try again. This problems can lead to deathly races on moderate (4-ways) SMP environment, leading to easy panic or deadlocks. The 24-ways of the reporter, could easilly panic, with completely normal workload, almost daily. gianni@ kindly wrote the following prof-of-concept which can panic a FreeBSD machine in less than one hour, in smaller SMP: http://www.freebsd.org/~attilio/callout/test.c Reported by: Nicholas Esborn <nick at desert dot net>, DesertNet In collabouration with: gianni, pho, Nicholas Esborn Reviewed by: jhb MFC after: 1 week (*) * Usually, I would aim for a larger MFC timeout, but I really want this in before 8.2-RELEASE, thus re@ accepted a shorter timeout as a special case for this patch
* - Follow r216313, the sched_unlend_user_prio is no longer needed, alwaysdavidxu2010-12-294-77/+30
| | | | | | | use sched_lend_user_prio to set lent priority. - Improve pthread priority-inherit mutex, when a contender's priority is lowered, repropagete priorities, this may cause mutex owner's priority to be lowerd, in old code, mutex owner's priority is rise-only.
* Teach ddb "show mount" about MNTK_SUJ flag.kib2010-12-271-0/+1
|
* Correct the order of the arguments to vm_fault_quick_hold_pages().alc2010-12-261-1/+1
|
* Introduce and use a new VM interface for temporarily pinning pages. Thisalc2010-12-253-62/+14
| | | | | | | new interface replaces the combined use of vm_fault_quick() and pmap_extract_and_hold() throughout the kernel. In collaboration with: kib@
* Enlarge hash table for new condition variable.davidxu2010-12-231-2/+2
|
* MFp4:davidxu2010-12-221-15/+105
| | | | | | | | | | | | | | | - Add flags CVWAIT_ABSTIME and CVWAIT_CLOCKID for umtx kernel based condition variable, this should eliminate an extra system call to get current time. - Add sub-function UMTX_OP_NWAKE_PRIVATE to wake up N channels in single system call. Create userland sleep queue for condition variable, in most cases, thread will wait in the queue, the pthread_cond_signal will defer thread wakeup until the mutex is unlocked, it tries to avoid an extra system call and a extra context switch in time window of pthread_cond_signal and pthread_mutex_unlock. The changes are part of process-shared mutex project.
* Initialize fp_location for explicitly managed fail points, and pushmdf2010-12-211-2/+3
| | | | | | | | | | | | | | | the parentheses around the location for simple fail points into the location string. This makes the print on fail point set more consistent between the two versions. Also fix up fail.h a little for style(9): only use one of sys/param.h and sys/types.h, and use the existing __XSTRING() macro instead of rolling our own. Also fix up a few tabs on changed and nearby lines. Lastly, since KFAIL_POINT_{BEGIN,END} are not meant for use outside this file, just eliminate the macros entirely. MFC after: 1 week
* Move the fail_point_entry definition from fail.h to kern_fail.c, whichmdf2010-12-211-9/+37
| | | | | | | allows putting the enumeration constants of fail point types with the text string that matches them. MFC after: 1 week
* - Introduce the Hhook (Helper Hook) KPI. The KPI is closely modelled on pfil(9),lstewart2010-12-212-0/+928
| | | | | | | | | | | | | | | | | | | | | | | | | | | | and in many respects can be thought of as a more generic superset of pfil. Hhook provides a way for kernel subsystems to export hook points that Khelp modules can hook to provide enhanced or new functionality to the kernel. The KPI has been designed to ensure hook points pose no noticeable overhead when no hook functions are registered. - Introduce the Khelp (Kernel Helpers) KPI. Khelp provides a framework for managing Khelp modules, which indirectly use the Hhook KPI to register their hook functions with hook points of interest within the kernel. Khelp modules aim to provide a structured way to dynamically extend the kernel at runtime in an ABI preserving manner. Depending on the subsystem providing hook points, a Khelp module may be able to associate per-object data for maintaining relevant state between hook calls. - pjd's Object Specific Data (OSD) KPI is used to manage the per-object data allocated to Khelp modules. Create a new "OSD_KHELP" OSD type for use by the Khelp framework. - Bump __FreeBSD_version to 900028 to mark the introduction of the new KPIs. In collaboration with: David Hayes <dahayes at swin edu au> and Grenville Armitage <garmitage at swin edu au> Sponsored by: FreeBSD Foundation Reviewed by: bz, others along the way MFC after: 3 months
* Introduce vm_fault_hold() and use it to (1) eliminate a long-standing racealc2010-12-201-63/+17
| | | | | | | | | | condition in proc_rwmem() and to (2) simplify the implementation of the cxgb driver's vm_fault_hold_user_pages(). Specifically, in proc_rwmem() the requested read or write could fail because the targeted page could be reclaimed between the calls to vm_fault() and vm_page_hold(). In collaboration with: kib@ MFC after: 6 weeks
* Implement and use a single optimized function for unholding a set of pages.alc2010-12-172-18/+4
| | | | Reviewed by: kib@
* Add back a bounds check on valid idle priorities that was lost in anjhb2010-12-171-8/+6
| | | | | | | | | earlier commit. While here, move the thread lock down in rtp_to_pri(). It is not needed for all of the priority value checks and the computation of newpri. Reported by: swell.k @ gmail MFC after: 3 days
* One of the compat32 functions was copying in a raw timespec, instead ofmdf2010-12-151-2/+1
| | | | | | | | a 32-bit one. This can cause weird timeout issues, as the copying reads garbage from the user. Code by: Deepak Veliath <deepak dot veliath at isilon dot com> MFC after: 1 week
* Just pass M_ZERO to malloc(9) instead of clearing allocated memory separately.pjd2010-12-141-2/+1
|
* Adapt filesystem-independent NFSv4 ACL code (used by UFS, but not by ZFS)trasz2010-12-131-63/+258
| | | | | | | | | | | | to PSARC/2010/029. In short, the semantics is simplified - "weird stuff" no longer happens after chmod, entries don't get duplicated during inheritance, and trivial ACLs no longer contain three "DENY" entries, which is also more friendly to MS Windows. By default, UFS keeps using old semantics. To change it, set sysctl vfs.acl_nfs4_old_semantics to 0. I'll flip the switch when ZFSv28 hits the tree, to keep these two in sync - ZFS v28 uses PSARC semantics, and ZFS v15 uses the old one.
* Fix race in devfs by using LIST_FIRST() instead ofhselasky2010-12-111-2/+2
| | | | | | | | | LIST_FOREACH_SAFE() when freeing the devfs private data entries. Reviewed by: kib MFC after: 3 days Approved by: thompsa (mentor)
* Refactor fork1() to make it easier to follow. No functional changes.trasz2010-12-101-191/+220
| | | | | Reviewed by: kib (earlier version) Tested by: pho
* Don't tie ct_debug to bootverbose. Provide a sysctl to turn it on or off.bz2010-12-091-1/+3
| | | | | | Switch the default to always off. Reviewed by: kib
* MFp4:davidxu2010-12-091-3/+42
| | | | | The unit number allocator reuses ID too fast, this may hide bugs in other code, add a ring buffer to delay freeing a thread ID.
* MFp4:davidxu2010-12-096-30/+33
| | | | | | | | | It is possible a lower priority thread lending priority to higher priority thread, in old code, it is ignored, however the lending should always be recorded, add field td_lend_user_pri to fix the problem, if a thread does not have borrowed priority, its value is PRI_MAX. MFC after: 1 week
* Add a KASSERT to make it obvious when fork_norfproc() is to be called,trasz2010-12-061-1/+3
| | | | | | | | and set *procp to NULL in all cases. Previously, it was not being set in the ERESTART case. This is effectively no-op, since its value is ignored by callers in the error case. Reviewed by: kib@
* Fix style bug introduced by previous commit.trasz2010-12-061-1/+1
|
* Improve readability by factoring out the !RFPROC case. While here,trasz2010-12-061-59/+57
| | | | | | turn K&R function definitions into ANSI. No functional changes. Reviewed by: kib@
* Trim whitespaces at the end of lines. Use the commit to recordkib2010-12-031-2/+2
| | | | | | | | | | | | | | | | | | | | | | proper log message for r216150. MFC after: 1 week If unix socket has a unix socket attached as the rights that has a unix socket attached as the rights that has a unix socket attached as the rights ... Kernel may overflow the stack on attempt to close such socket. Only close the rights file in the context of the current close if the file is not unix domain socket. Otherwise, postpone the work to taskqueue, preventing unlimited recursion. The pass of the unix domain sockets over the SCM_RIGHTS message control is not widely used, and more, the close of the socket with still attached rights is mostly an application failure. The change should not affect the performance of typical users of SCM_RIGHTS. Reviewed by: jeff, rwatson
* Reviewed by: jeff, rwatsonkib2010-12-031-5/+74
| | | | MFC after: 1 week
* Replace pointer to "struct uidinfo" with pointer to "struct ucred"trasz2010-12-021-2/+2
| | | | | | | | | in "struct vm_object". This is required to make it possible to account for per-jail swap usage. Reviewed by: kib@ Tested by: pho@ Sponsored by: FreeBSD Foundation
* removed tag is '-', not '+'.imp2010-12-021-2/+1
| | | | remove extra return.
* Remove useless NULL checks for M_WAITOK mallocs.trasz2010-12-022-19/+0
|
* Remove redundant (and bogus) insertion of pnp info when announcing newimp2010-11-301-37/+2
| | | | | | | and retiring devices. That's already inserted elsewhere. Submitted by: n_hibma MFC after: 3 days
* Fix uninitialized variable warning that shows on Tinderbox but not mymdf2010-11-291-1/+1
| | | | | | setup. (??) Submitted by: Michael Butler <imb at protected-networks dot net>
* Do not hold the sysctl lock across a call to the handler. This fixes amdf2010-11-291-27/+67
| | | | | | | | | | general LOR issue where the sysctl lock had no good place in the hierarchy. One specific instance is #284 on http://sources.zabbadoz.net/freebsd/lor.html . Reviewed by: jhb MFC after: 1 month X-MFC-note: split oid_refcnt field for oid_running to preserve KBI
* Slightly modify the logic in sysctl_find_oid to reduce the indentation.mdf2010-11-291-19/+22
| | | | | | There should be no functional change. MFC after: 3 days
* Use the SYSCTL_CHILDREN macro in kern_sysctl.c to help de-obfuscate themdf2010-11-291-7/+6
| | | | | | code. MFC after: 3 days
* Account i/o done on cdevs.kib2010-11-251-2/+5
| | | | | Reported and tested by: Adam Vande More <amvandemore gmail com> MFC after: 1 week
* Allow shared-locked vnode to be passed to vunref(9).kib2010-11-241-5/+15
| | | | | | | | | | When shared-locked vnode is supplied as an argument to vunref(9) and resulting usecount is 0, set VI_OWEINACT and do not try to upgrade vnode lock. The later could cause vnode unlock, allowing the vnode to be reclaimed meantime. Tested by: pho MFC after: 1 week
* taskqueue: drop unused tq_name fieldavg2010-11-231-3/+1
| | | | | | | | | | | | tq_name was used write-only and besides it was just a pointer, so it could point to some garbage in a temporary buffer that's gone. This change shouldn't change KPI/KBI as struct taskqueue is private to subr_taskqueue.c. If we find a need for tq_name it can be resurrected at any moment. taskqueue_create() interface is preserved for this purpose. Suggested by: jhb MFC after: 10 days
* Update MNT_ROOTFS comments after changes in the root mount logic.pluknet2010-11-231-2/+4
| | | | | | Reported by: arundel Suggested by: marcel (phrasing) Approved by: kib (mentor)
* Add parentheses for clarity. The parentheses around the two terms of the &&cperciva2010-11-231-1/+1
| | | | | | | are unnecessary but I'm leaving them in for the sake of avoiding confusion (I confuse easily). Submitted by: bde
* After some off-list discussion, revert a number of changes to thedim2010-11-224-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | DPCPU_DEFINE and VNET_DEFINE macros, as these cause problems for various people working on the affected files. A better long-term solution is still being considered. This reversal may give some modules empty set_pcpu or set_vnet sections, but these are harmless. Changes reverted: ------------------------------------------------------------------------ r215318 | dim | 2010-11-14 21:40:55 +0100 (Sun, 14 Nov 2010) | 4 lines Instead of unconditionally emitting .globl's for the __start_set_xxx and __stop_set_xxx symbols, only emit them when the set_vnet or set_pcpu sections are actually defined. ------------------------------------------------------------------------ r215317 | dim | 2010-11-14 21:38:11 +0100 (Sun, 14 Nov 2010) | 3 lines Apply the STATIC_VNET_DEFINE and STATIC_DPCPU_DEFINE macros throughout the tree. ------------------------------------------------------------------------ r215316 | dim | 2010-11-14 21:23:02 +0100 (Sun, 14 Nov 2010) | 2 lines Add macros to define static instances of VNET_DEFINE and DPCPU_DEFINE.
* Style fix.attilio2010-11-221-3/+2
| | | | | | | | Sponsored by: Sandvine Incorporated Requested by: jhb Reviewed by: jhb MFC after: 1 week X-MFC: 215544
* Add the ability for GDB to printout the thread name along with otherattilio2010-11-222-0/+13
| | | | | | | | | | | | | | | | | | | | thread specific informations. In order to do that, and in order to avoid KBI breakage with existing infrastructure the following semantic is implemented: - For live programs, a new member to the PT_LWPINFO is added (pl_tdname) - For cores, a new ELF note is added (NT_THRMISC) that can be used for storing thread specific, miscellaneous, informations. Right now it is just popluated with a thread name. GDB, then, retrieves the correct informations from the corefile via the BFD interface, as it groks the ELF notes and create appropriate pseudo-sections. Sponsored by: Sandvine Incorporated Tested by: gianni Discussed with: dim, kan, kib MFC after: 2 weeks
* In tc_windup, handle the case where the previous call to tc_windup wascperciva2010-11-221-0/+10
| | | | | | | | | | | | | more than 1s earlier. Prior to this commit, the computation of th_scale * delta (which produces a 64-bit value equal to the time since the last tc_windup call in units of 2^(-64) seconds) would overflow and any complete seconds would be lost. We fix this by repeatedly converting tc_frequency units of timecounter to one seconds; this is not exactly correct, since it loses the NTP adjustment, but if we find ourselves going more than 1s at a time between clock interrupts, losing a few seconds worth of NTP adjustments is the least of our problems...
OpenPOWER on IntegriCloud