summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_descrip.c
Commit message (Collapse)AuthorAgeFilesLines
* Back out my lats commit of locking down a socket, it conflicts with hsu's work.tanimura2002-05-311-5/+2
| | | | Requested by: hsu
* Lock down a socket, milestone 1.tanimura2002-05-201-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | o Add a mutex (sb_mtx) to struct sockbuf. This protects the data in a socket buffer. The mutex in the receive buffer also protects the data in struct socket. o Determine the lock strategy for each members in struct socket. o Lock down the following members: - so_count - so_options - so_linger - so_state o Remove *_locked() socket APIs. Make the following socket APIs touching the members above now require a locked socket: - sodisconnect() - soisconnected() - soisconnecting() - soisdisconnected() - soisdisconnecting() - sofree() - soref() - sorele() - sorwakeup() - sotryfree() - sowakeup() - sowwakeup() Reviewed by: alfred
* More s/file system/filesystem/gtrhodes2002-05-161-1/+1
|
* Make funsetown() take a 'struct sigio **' so that the locking canalfred2002-05-061-26/+45
| | | | | | | | | | | | | | | | be done internally. Ensure that no one can fsetown() to a dying process/pgrp. We need to check the process for P_WEXIT to see if it's exiting. Process groups are already safe because there is no such thing as a pgrp zombie, therefore the proctree lock completely protects the pgrp from having sigio structures associated with it after it runs funsetownlst. Add sigio lock to witness list under proctree and allproc, but over proc and pgrp. Seigo Tanimura helped with this.
* As malloc(9) and free(9) are now Giant-free, remove the Giant locktanimura2002-05-031-4/+0
| | | | across malloc(9) and free(9) of a pgrp or a session.
* Fix the lock order reversal between the sigio lock and a process/pgrp lock intanimura2002-05-031-2/+6
| | | | funsetownlst() by locking the sigio lock across funsetownlst().
* Redo the sigio locking.alfred2002-05-011-13/+13
| | | | | | | | | | | Turn the sigio sx into a mutex. Sigio lock is really only needed to protect interrupts from dereferencing the sigio pointer in an object when the sigio itself is being destroyed. In order to do this in the most unintrusive manner change pgsigio's sigio * argument into a **, that way we can lock internally to the function.
* Fix indention which I did wrong in a previous commit.asmodai2002-04-291-1/+1
| | | | Submitted by: bde
* Add a global sx sigio_lock to protect the pointer to the sigio objecttanimura2002-04-271-0/+2
| | | | | | | | | | of a socket. This avoids lock order reversal caused by locking a process in pgsigio(). sowakeup() and the callers of it (sowwakeup, soisconnected, etc.) now require sigio_lock to be locked. Provide sowwakeup_locked(), soisconnected_locked(), and so on in case where we have to modify a socket and wake up a process atomically.
* Don't FILEDESC_LOCK around calls to falloc().alfred2002-04-221-2/+0
|
* Push down Giant for setpgid(), setsid() and aio_daemon(). Giant protects onlytanimura2002-04-201-0/+4
| | | | malloc(9) and free(9).
* When exec'ing a set[ug]id program, make sure that the stdio file descriptorsnectar2002-04-191-0/+65
| | | | | | | | (0, 1, 2) are allocated by opening /dev/null for any which are not already open. Reviewed by: alfred, phk MFC after: 2 days
* Lock proctree_lock instead of pgrpsess_lock.jhb2002-04-161-3/+3
|
* Use the correct macros for F_SETFD/F_GETFD instead of magic numbers.asmodai2002-04-131-2/+3
| | | | | | | | | Reflect that fact in the manual page. PR: 12723 Submitted by: Peter Jeremy <peter.jeremy@alcatel.com.au> Approved by: bde MFC after: 2 weeks
* Change callers of mtx_init() to pass in an appropriate lock type name. Injhb2002-04-041-2/+2
| | | | | | | most cases NULL is passed, but in some cases such as network driver locks (which use the MTX_NETWORK_LOCK macro) and UMA zone locks, a name is used. Tested on: i386, alpha, sparc64
* The description of fd_mtx is "filedesc structure."tanimura2002-03-291-2/+2
|
* Remove references to vm_zone.h and switch over to the new uma API.jeff2002-03-201-1/+1
| | | | | Also, remove maxsockets. If you look carefully you'll notice that the old zone allocator never honored this anyway.
* Remove __P.alfred2002-03-191-11/+11
|
* This is the first part of the new kernel memory allocator. This replacesjeff2002-03-191-4/+10
| | | | | | malloc(9) and vm_zone with a slab like allocator. Reviewed by: arch@
* Close a race when vfs_syscalls.c:checkdirs() runs.alfred2002-03-191-1/+7
| | | | | To do this protect the filedesc pointer in the proc with PROC_LOCK in both checkdirs() and kern_descrip.c:fdfree().
* Giant pushdown for read/write/pread/pwrite syscalls.alfred2002-03-151-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | kern/kern_descrip.c: Aquire Giant in fdrop_locked when file refcount hits zero, this removes the requirement for the caller to own Giant for the most part. kern/kern_ktrace.c: Aquire Giant in ktrgenio, simplifies locking in upper read/write syscalls. kern/vfs_bio.c: Aquire Giant in bwillwrite if needed. kern/sys_generic.c Giant pushdown, remove Giant for: read, pread, write and pwrite. readv and writev aren't done yet because of the possible malloc calls for iov to uio processing. kern/sys_socket.c Grab giant in the socket fo_read/write functions. kern/vfs_vnops.c Grab giant in the vnode fo_read/write functions.
* Simple p_ucred -> td_ucred changes to start using the per-thread ucredjhb2002-02-271-2/+2
| | | | reference.
* Lock struct pgrp, session and sigio.tanimura2002-02-231-18/+91
| | | | | | | | | | | | | | | | | | | | | | | | | New locks are: - pgrpsess_lock which locks the whole pgrps and sessions, - pg_mtx which protects the pgrp members, and - s_mtx which protects the session members. Please refer to sys/proc.h for the coverage of these locks. Changes on the pgrp/session interface: - pgfind() needs the pgrpsess_lock held. - The caller of enterpgrp() is responsible to allocate a new pgrp and session. - Call enterthispgrp() in order to enter an existing pgrp. - pgsignal() requires a pgrp lock held. Reviewed by: jhb, alfred Tested on: cvsup.jp.FreeBSD.org (which is a quad-CPU machine running -current)
* Fix broken Giant locking protocol introduced in rev 1.114. You cannotpeter2002-02-081-0/+1
| | | | | unlock Giant if it is not locked in the first place. This make the nfstat(2) syscall (#278) a nice panic(2) implementation.
* Remove bogus assertion in dup2 that can lead to panics when kernelalfred2002-02-011-2/+0
| | | | | | | | | | | | | | | | | threads race for a file slot. dup2(2) incorrectly assumes that if it needs to grow the ofiles array that it will get what it wants. This assertion was valid before we allowed shared filedescriptor tables but is now incorrect. The assertion can trigger superfolous panics if the thread doing a dup2 looses a race with another thread while possibly blocked in the MALLOC call in fdalloc. Another thread may grab the slot we are requesting which makes fdalloc return something other than what we asked for, this will triggering the bogus assertion. MFC after: 2 weeks Reviewed by: phk
* Avoid lock order reversal filedesc/Giant when calling FREE() in fdallocalfred2002-02-011-0/+2
| | | | | | by unlocking the filedesc before calling FREE(). Submitted by: bde
* Attempt to fixup select(2) and poll(2), this should fix some races withalfred2002-01-291-3/+1
| | | | | | | | | | | | | | | | | | | other threads as well as speed up the interfaces. To fix the race and accomplish the speedup, remove selholddrop and pollholddrop. The entire concept is somewhat bogus because holding the individual struct file pointers offers us no guarantees that another thread context won't close it on us thereby removing our access to our own reference. Selholddrop and pollholddrop also would do multiple locks and unlocks of mutexes _per-file_ in the fd arrays to be scanned, this needed to be sped up. Instead of using selholddrop and pollholddrop, simply hold the filedesc lock over the selscan and pollscan functions. This should protect us against close(2)'s on the files as reduce the multiple lock/unlock pairs per fd into a single lock over the filedesc.
* Backout 1.120, EINVAL isn't a proper error return when the passed fd isalfred2002-01-291-1/+1
| | | | | | | negative, the 'pointer' referred to by the manpage is actually the struct file's f_offset field. Pointed out by: bde
* in fget() return EINVAL when the descriptor requested is negative.alfred2002-01-231-1/+1
|
* use mutex pools for "struct file" locking.alfred2002-01-201-2/+1
| | | | fix indentation of FILE_LOCK/UNLOCK macros while I'm here.
* Push down Giant in dup(2) and dup2(2), Giant is only needed whenalfred2002-01-151-16/+17
| | | | | calling closef() in the case of dup2(2) duping over a descriptor and when fdalloc must grow or free a filedesc.
* Replace ffind_* with fget calls.alfred2002-01-141-120/+67
| | | | | | | | Make fget MPsafe. Make fgetvp and fgetsock use the fget subsystem to reduce code bloat. Push giant down in fpathconf().
* Comment fdrop and fdrop_locked functions.alfred2002-01-131-0/+9
|
* Implement ffind_hold using ffind_lock.alfred2002-01-131-11/+3
| | | | Recommended by: jhb
* SMP Lock struct file, filedesc and the global file list.alfred2002-01-131-49/+292
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Seigo Tanimura (tanimura) posted the initial delta. I've polished it quite a bit reducing the need for locking and adapting it for KSE. Locks: 1 mutex in each filedesc protects all the fields. protects "struct file" initialization, while a struct file is being changed from &badfileops -> &pipeops or something the filedesc should be locked. 1 mutex in each struct file protects the refcount fields. doesn't protect anything else. the flags used for garbage collection have been moved to f_gcflag which was the FILLER short, this doesn't need locking because the garbage collection is a single threaded container. could likely be made to use a pool mutex. 1 sx lock for the global filelist. struct file * fhold(struct file *fp); /* increments reference count on a file */ struct file * fhold_locked(struct file *fp); /* like fhold but expects file to locked */ struct file * ffind_hold(struct thread *, int fd); /* finds the struct file in thread, adds one reference and returns it unlocked */ struct file * ffind_lock(struct thread *, int fd); /* ffind_hold, but returns file locked */ I still have to smp-safe the fget cruft, I'll get to that asap.
* When removing kqueue descriptors from the descriptor table during a fork,jlemon2001-12-141-3/+8
| | | | | | update fd_freefile and fd_lastfile as well, to keep things in sync. Pointed out by: Debbie Chu <dchu@juniper.net>
* Give struct socket structures a ref counting interface similar todillon2001-11-171-0/+47
| | | | | | | vnodes. This will hopefully serve as a base from which we can expand the MP code. We currently do not attempt to obtain any mutex or SX locks, but the door is open to add them when we nail down exactly how that part of it is going to work.
* remove holdfp()dillon2001-11-141-37/+127
| | | | | | | | | | | | | | | | | | | Replace uses of holdfp() with fget*() or fgetvp*() calls as appropriate introduce fget(), fget_read(), fget_write() - these functions will take a thread and file descriptor and return a file pointer with its ref count bumped. introduce fgetvp(), fgetvp_read(), fgetvp_write() - these functions will take a thread and file descriptor and return a vref()'d vnode. *_read() requires that the file pointer be FREAD, *_write that it be FWRITE. This continues the cleanup of struct filedesc and struct file access routines which, when are all through with it, will allow us to then make the API calls MP safe and be able to move Giant down into the fo_* functions.
* Change the kernel's ucred API as follows:jhb2001-10-111-4/+2
| | | | | | | | - crhold() returns a reference to the ucred whose refcount it bumps. - crcopy() now simply copies the credentials from one credential to another and has no return value. - a new crshared() primitive is added which returns true if a ucred's refcount is > 1 and false (0) otherwise.
* When FREE()ing kqueue related structures, charge them to the correct bucket.jlemon2001-09-301-3/+3
| | | | | Submitted by: iedowse Forgotten by: jlemon
* If an incoming struct proc could have been NULL before, tehn don'tjulian2001-09-121-4/+5
| | | | | | | | | | | | automatically change the code to add struct proc *p = td->td_proc; because now 'td' is probably capable of being NULL too. I expect to see more of this kind of error during the 'weeding' process. It's too easy to make. (junior hacker project.. look for these :-) Submitted by: mark Peek <mp@freebsd.org>
* KSE Milestone 2julian2001-09-121-138/+146
| | | | | | | | | | | | | | Note ALL MODULES MUST BE RECOMPILED make the kernel aware that there are smaller units of scheduling than the process. (but only allow one thread per process at this time). This is functionally equivalent to teh previousl -current except that there is a thread associated with each process. Sorry john! (your next MFC will be a doosie!) Reviewed by: peter@freebsd.org, dillon@freebsd.org X-MFC after: ha ha ha ha
* Giant Pushdown. Saved the worst P4 tree breakage for last.dillon2001-09-011-64/+176
| | | | | | | | | | | | reboot() getpriority() setpriority() rtprio() osetrlimit() ogetrlimit() setrlimit() getrlimit() getrusage() getpid() getppid() getpgrp() getpgid() getsid() getgid() getegid() getgroups() setsid() setpgid() setuid() seteuid() setgid() setegid() setgroups() setreuid() setregid() setresuid() setresgid() getresuid() getresgid () __setugid() getlogin() setlogin() modnext() modfnext() modstat() modfind() kldload() kldunload() kldfind() kldnext() kldstat() kldfirstmod() kldsym() getdtablesize() dup2() dup() fcntl() close() ofstat() fstat() nfsstat() fpathconf() flock()
* advlock: simplify overflow checksache2001-08-291-4/+3
|
* Move <machine/*> after <sys/*>ache2001-08-231-3/+9
| | | | | | Add missing fdrop() before EOVERFLOW Pointed by: bde
* Detect off_t EOVERFLOW of start/end offsets calculations for adv. lock,ache2001-08-231-2/+15
| | | | as POSIX require.
* Remove the fildesc_clone() function and its associated unnecessary code.chris2001-08-061-23/+0
| | | | | | | | | | | | It didn't implement the proper /dev/fd functionality (which would be to include in the directory listing /dev/fd/n if the process has fd n open) anyway. Anything needing access to /dev/fd/n where n > 2 can use the optional fdescfs module, which implements this properly and does not cause any trouble with devfs. Discussed with: phk
* o Merge contents of struct pcred into struct ucred. Specifically, add therwatson2001-05-251-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | real uid, saved uid, real gid, and saved gid to ucred, as well as the pcred->pc_uidinfo, which was associated with the real uid, only rename it to cr_ruidinfo so as not to conflict with cr_uidinfo, which corresponds to the effective uid. o Remove p_cred from struct proc; add p_ucred to struct proc, replacing original macro that pointed. p->p_ucred to p->p_cred->pc_ucred. o Universally update code so that it makes use of ucred instead of pcred, p->p_ucred instead of p->p_pcred, cr_ruidinfo instead of p_uidinfo, cr_{r,sv}{u,g}id instead of p_*, etc. o Remove pcred0 and its initialization from init_main.c; initialize cr_ruidinfo there. o Restruction many credential modification chunks to always crdup while we figure out locking and optimizations; generally speaking, this means moving to a structure like this: newcred = crdup(oldcred); ... p->p_ucred = newcred; crfree(oldcred); It's not race-free, but better than nothing. There are also races in sys_process.c, all inter-process authorization, fork, exec, and exit. o Remove sigio->sio_ruid since sigio->sio_ucred now contains the ruid; remove comments indicating that the old arrangement was a problem. o Restructure exec1() a little to use newcred/oldcred arrangement, and use improved uid management primitives. o Clean up exit1() so as to do less work in credential cleanup due to pcred removal. o Clean up fork1() so as to do less work in credential cleanup and allocation. o Clean up ktrcanset() to take into account changes, and move to using suser_xxx() instead of performing a direct uid==0 comparision. o Improve commenting in various kern_prot.c credential modification calls to better document current behavior. In a couple of places, current behavior is a little questionable and we need to check POSIX.1 to make sure it's "right". More commenting work still remains to be done. o Update credential management calls, such as crfree(), to take into account new ruidinfo reference. o Modify or add the following uid and gid helper routines: change_euid() change_egid() change_ruid() change_rgid() change_svuid() change_svgid() In each case, the call now acts on a credential not a process, and as such no longer requires more complicated process locking/etc. They now assume the caller will do any necessary allocation of an exclusive credential reference. Each is commented to document its reference requirements. o CANSIGIO() is simplified to require only credentials, not processes and pcreds. o Remove lots of (p_pcred==NULL) checks. o Add an XXX to authorization code in nfs_lock.c, since it's questionable, and needs to be considered carefully. o Simplify posix4 authorization code to require only credentials, not processes and pcreds. Note that this authorization, as well as CANSIGIO(), needs to be updated to use the p_cansignal() and p_cansched() centralized authorization routines, as they currently do not take into account some desirable restrictions that are handled by the centralized routines, as well as being inconsistent with other similar authorization instances. o Update libkvm to take these changes into account. Obtained from: TrustedBSD Project Reviewed by: green, bde, jhb, freebsd-arch, freebsd-audit
* Undo part of the tangle of having sys/lock.h and sys/mutex.h included inmarkm2001-05-011-0/+2
| | | | | | | | | | | other "system" header files. Also help the deprecation of lockmgr.h by making it a sub-include of sys/lock.h and removing sys/lockmgr.h form kernel .c files. Sort sys/*.h includes where possible in affected files. OK'ed by: bde (with reservations)
* Change the pfind() and zpfind() functions to lock the process that theyjhb2001-04-241-1/+4
| | | | | | find before releasing the allproc lock and returning. Reviewed by: -smp, dfr, jake
OpenPOWER on IntegriCloud