summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_conf.c
Commit message (Collapse)AuthorAgeFilesLines
* Make it atomic for the devfs_populate_loop() to see the setting ofkib2008-07-111-1/+2
| | | | | | | | | | | | SI_ALIAS flag and initialization of the si_parent when alias is created. Assert that supplied parent device is not NULL. Both situations could cause NULL dereference in the devfs_populate_loop() when creating a symlink for SI_ALIAS'ed device. Namely, cdp->cdp_c.si_parent may be NULL. Reported by: mav MFC after: 2 weeks
* Struct cdev is always the member of the struct cdev_priv. When devfskib2008-06-161-6/+6
| | | | | | | | | | | needed to promote cdev to cdev_priv, the si_priv pointer was followed. Use member2struct() to calculate address of the wrapping cdev_priv. Rename si_priv to __si_reserved. Tested by: pho Reviewed by: ed MFC after: 2 weeks
* Turn dev2unit(), minor(), unit2minor() and minor2unit() into macro's.ed2008-06-121-35/+0
| | | | | | | | | | | | | Now that we got rid of the minor-to-unit conversion and the constraints on device minor numbers, we can convert the functions that operate on minor and unit numbers to simple macro's. The unit2minor() and minor2unit() macro's are now no-ops. The ZFS code als defined a macro named `minor'. Change the ZFS code to use umajor() and uminor() here, as it is the correct approach to do this. Also add $FreeBSD$ to keep SVN happy. Approved by: philip (mentor), pjd
* Don't enforce unique device minor number policy anymore.ed2008-06-111-4/+9
| | | | | | | | | | | | | | | | | | | | | | | Except for the case where we use the cloner library (clone_create() and friends), there is no reason to enforce a unique device minor number policy. There are various drivers in the source tree that allocate unr pools and such to provide minor numbers, without using them themselves. Because we still need to support unique device minor numbers for the cloner library, introduce a new flag called D_NEEDMINOR. All cdevsw's that are used in combination with the cloner library should be marked with this flag to make the cloning work. This means drivers can now freely use si_drv0 to store their own flags and state, making it effectively the same as si_drv1 and si_drv2. We still keep the minor() and dev2unit() routines around to make drivers happy. The NTFS code also used the minor number in its hash table. We should not do this anymore. If the si_drv0 field would be changed, it would no longer end up in the same list. Approved by: philip (mentor)
* Remove the distinction between device minor and unit numbers.ed2008-05-291-11/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Even though we got rid of device major numbers some time ago, device drivers still need to provide unique device minor numbers to make_dev(). These numbers are only used inside the kernel. They are not related to device major and minor numbers which are visible in devfs. These are actually based on the inode number of the device. It would eventually be nice to remove minor numbers entirely, but we don't want to be too agressive here. Because the 8-15 bits of the device number field (si_drv0) are still reserved for the major number, there is no 1:1 mapping of the device minor and unit numbers. Because this is now unused, remove the restrictions on these numbers. The MAXMAJOR definition was actually used for two purposes. It was used to convert both the userspace and kernelspace device numbers to their major/minor pair, which is why it is now named UMINORMASK. minor2unit() and unit2minor() have now become useless. Both minor() and dev2unit() now serve the same purpose. We should eventually remove some of them, at least turning them into macro's. If devfs would become completely minor number unaware, we could consider using si_drv0 directly, just like si_drv1 and si_drv2. Approved by: philip (mentor)
* Assert that si_threadcount > 0 before decrementing it. This helps catchingkib2008-05-231-0/+2
| | | | | | | the improper use of the dev_refthread/dev_relthread. Tested by: pho MFC after: 1 week
* Implement the per-open file data for the cdev.kib2008-05-211-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The patch does not change the cdevsw KBI. Management of the data is provided by the functions int devfs_set_cdevpriv(void *priv, cdevpriv_dtr_t dtr); int devfs_get_cdevpriv(void **datap); void devfs_clear_cdevpriv(void); All of the functions are supposed to be called from the cdevsw method contexts. - devfs_set_cdevpriv assigns the priv as private data for the file descriptor which is used to initiate currently performed driver operation. dtr is the function that will be called when either the last refernce to the file goes away, the device is destroyed or devfs_clear_cdevpriv is called. - devfs_get_cdevpriv is the obvious accessor. - devfs_clear_cdevpriv allows to clear the private data for the still open file. Implementation keeps the driver-supplied pointers in the struct cdev_privdata, that is referenced both from the struct file and struct cdev, and cannot outlive any of the referee. Man pages will be provided after the KPI stabilizes. Reviewed by: jhb Useful suggestions from: jeff, antoine Debugging help and tested by: pho MFC after: 1 month
* Add the devctl notifications for the cdev create/destroy events.kib2008-05-141-0/+42
| | | | | Based on the submission by: Andriy Gapon <avg icyb net ua> MFC after: 2 weeks
* Add two missed chunks from the rev. 1.210, for the giant_read() andkib2008-04-021-4/+2
| | | | | | | giant_ioctl(). PR: kern/122287 MFC after: 3 days
* Fix two races in the handling of the d_gianttrick for the D_NEEDGIANTkib2008-03-171-35/+121
| | | | | | | | | | | | | | | | | | | | | | | | | | drivers. In the giant_XXX wrappers for the device methods of the D_NEEDGIANT drivers, do not dereference the cdev->si_devsw. It is racing with the destroy_devl() clearing of the si_devsw. Instead, use the dev_refthread() and return ENXIO for the destroyed device. [1] The check for the D_INIT in the prep_cdevsw() was not synchronized with the call of the fini_cdevsw() in destroy_devl(), that under rapid device creation/destruction may result in the use of uninitialized cdevsw [2]. Change the protocol for the prep_cdevsw(), requiring it to be called under dev_mtx, where the check for D_INIT is done. Do not free the memory allocated for the gianttrick cdevsw while holding the dev_mtx, put it into the free list to be freed later. Reuse the d_gianttrick pointer to keep the size and layout of the struct cdevsw (requested by phk). Free the memory in the dev_unlock_and_free(), and do all the free after the dev_mtx is dropped (suggested by jhb). Reported by: bsdimp + many [1], pho [2] Reviewed by: phk, jhb Tested by: pho MFC after: 1 week
* Apply a workaround for the unkillable jail problem where some devices createdthompsa2007-12-051-0/+2
| | | | | | | | | | | within the jail are never freed. si_cred is only used by the MAC framework so make the cred reference conditional on it being compiled in, this is not a fix and will need to be reviewed for any new consumers of si_cred. This will quell some user complaint when using jails with a default kernel. Reviewed by: rwatson MFC after: 3 days
* Revert destroy_dev() to the state before destroy_dev_sched() was introduced.kib2007-07-051-8/+2
| | | | | | | Attempt to spawn destroy_dev_sched() from it causes inadmissible races. Requested by: tegge Approved by: re (kensmith)
* Since cdev mutex is after system map mutex in global lock order, free()kib2007-07-041-0/+2
| | | | | | | | | | | | | | | | | | shall not be called while holding cdev mutex. devfs_inos unrhdr has cdev as mutex, thus creating this LOR situation. Postpone calling free() in kern/subr_unit.c:alloc_unr() and nested functions until the unrhdr mutex is dropped. Save the freed items on the ppfree list instead, and provide the clean_unrhdrl() and clean_unrhdr() functions to clean the list. Call clean_unrhdrl() after devfs_create() calls immediately before dropping cdev mutex. devfs_create() is the only user of the alloc_unrl() in the tree. Reviewed by: phk Tested by: Peter Holm LOR: 80 Approved by: re (kensmith)
* Rev. 1.204 and 1.205 got an erronous version of destroy_dev() thatkib2007-07-031-6/+18
| | | | | | | | calls destroy_dev_sched() with cdev mutex locked. Commit the code that was actually tested. Pointy hat to: kib Approved by: re (implicit)
* Automatically detect deadlock condition in destroy_dev(), that is, ifkib2007-07-031-2/+8
| | | | | | | | | destroy_dev() is called from csw method, and no d_purge driver method is provided. Transform the direct call to destroy_dev() into destroy_dev_sched(). Reviewed by: njl (programming interface) Debugging help and testing by: Peter Holm Approved by: re (kensmith)
* Since rev. 1.199 of sys/kern/kern_conf.c, the thread that callskib2007-07-031-18/+147
| | | | | | | | | | | | | | | | | | | | | | | destroy_dev() from d_close() cdev method would self-deadlock. devfs_close() bump device thread reference counter, and destroy_dev() sleeps, waiting for si_threadcount to reach zero for cdev without d_purge method. destroy_dev_sched() could be used instead from d_close(), to schedule execution of destroy_dev() in another context. The destroy_dev_sched_drain() function can be used to drain the scheduled calls to destroy_dev_sched(). Similarly, drain_dev_clone_events() drains the events clone to make sure no lingering devices are left after dev_clone event handler deregistered. make_dev_credf(MAKEDEV_REF) function should be used from dev_clone event handlers instead of make_dev()/make_dev_cred() to ensure that created device has reference counter bumped before cdev mutex is dropped inside make_dev(). Reviewed by: tegge (early versions), njl (programming interface) Debugging help and testing by: Peter Holm Approved by: re (kensmith)
* devfs_free() calls free_unr(), that may sleep.kib2007-06-191-6/+34
| | | | | | | | | | | Postpone call to devfs_free() after cdev mutex is dropped. Reuse cdp_list link for queuing devices awaiting deletion in the cdevp_free_list. Reported by: Hans Petter Selasky <hselasky c2i net> Tested by: Peter Holm Approved by: re (kensmith) MFC after: 2 weeks
* Revert UF_OPENING workaround for CURRENT.kib2007-05-311-2/+2
| | | | | | | | | Change the VOP_OPEN(), vn_open() vnode operation and d_fdopen() cdev operation argument from being file descriptor index into the pointer to struct file. Proposed and reviewed by: jhb Reviewed by: daichi (unionfs) Approved by: re (kensmith)
* Use int instead of u_int for the 'extra' argument to thebms2007-02-021-1/+1
| | | | | | | | | clone_create() KPI. This fixes a signedness bug in unit number comparisons. Submitted by: imp, Landon Fuller PR: kern/105228 MFC after: 2 weeks
* Fix the race between devfs_fp_check and devfs_reclaim. Derefence thekib2006-10-201-0/+18
| | | | | | | | vnode' v_rdev and increment the dev threadcount , as well as clear it (in devfs_reclaim) under the dev_lock(). Reviewed by: tegge Approved by: pjd (mentor)
* Wait for thread count to reach zero in destroy_devl() even when no purgetegge2006-10-131-0/+6
| | | | | | | method is defined, to avoid memory being modified after free. Temporarily increase refcount in destroy_devl() to avoid a double free if dev_rel() is called while waiting for thread count to reach zero.
* Make the printfs relating to purging threads from a device less intrusive.phk2006-05-171-4/+3
|
* Novel idea, don't print a string if it is NULL!alfred2006-01-121-1/+2
| | | | | This protects people from loading _really_ old modules, like say from 5.x to a 6.x or 7.x system, like for instance right after an upgrade.
* Minor whitespace cleanup.bz2006-01-041-2/+2
|
* Move the initialization of the devmtx into the mutex_init() functionjhb2005-10-181-2/+1
| | | | | | | | | called during early init before cninit(). Tested on: i386, alpha, sparc64 Reviewed by: phk, imp Reported by: Divacky Roman xdivac02 at stud dot fit dot vutbr dot cz MFC after: 1 week
* Make sure the clone lists are sorted in the right order.phk2005-10-011-3/+5
| | | | | Explosion triggered by: pjd MFC: 3 days
* Rewamp DEVFS internals pretty severely [1].phk2005-09-191-39/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Give DEVFS a proper inode called struct cdev_priv. It is important to keep in mind that this "inode" is shared between all DEVFS mountpoints, therefore it is protected by the global device mutex. Link the cdev_priv's into a list, protected by the global device mutex. Keep track of each cdev_priv's state with a flag bit and of references from mountpoints with a dedicated usecount. Reap the benefits of much improved kernel memory allocator and the generally better defined device driver APIs to get rid of the tables of pointers + serial numbers, their overflow tables, the atomics to muck about in them and all the trouble that resulted in. This makes RAM the only limit on how many devices we can have. The cdev_priv is actually a super struct containing the normal cdev as the "public" part, and therefore allocation and freeing has moved to devfs_devs.c from kern_conf.c. The overall responsibility is (to be) split such that kern/kern_conf.c is the stuff that deals with drivers and struct cdev and fs/devfs handles filesystems and struct cdev_priv and their private liason exposed only in devfs_int.h. Move the inode number from cdev to cdev_priv and allocate inode numbers properly with unr. Local dirents in the mountpoints (directories, symlinks) allocate inodes from the same pool to guarantee against overlaps. Various other fields are going to migrate from cdev to cdev_priv in the future in order to hide them. A few fields may migrate from devfs_dirent to cdev_priv as well. Protect the DEVFS mountpoint with an sx lock instead of lockmgr, this lock also protects the directory tree of the mountpoint. Give each mountpoint a unique integer index, allocated with unr. Use it into an array of devfs_dirent pointers in each cdev_priv. Initially the array points to a single element also inside cdev_priv, but as more devfs instances are mounted, the array is extended with malloc(9) as necessary when the filesystem populates its directory tree. Retire the cdev alias lists, the cdev_priv now know about all the relevant devfs_dirents (and their vnodes) and devfs_revoke() will pick them up from there. We still spelunk into other mountpoints and fondle their data without 100% good locking. It may make better sense to vector the revoke event into the tty code and there do a destroy_dev/make_dev on the tty's devices, but that's for further study. Lots of shuffling of stuff and churn of bits for no good reason[2]. XXX: There is still nothing preventing the dev_clone EVENTHANDLER from being invoked at the same time in two devfs mountpoints. It is not obvious what the best course of action is here. XXX: comment out an if statement that lost its body, until I can find out what should go there so it doesn't do damage in the meantime. XXX: Leave in a few extra malloc types and KASSERTS to help track down any remaining issues. Much testing provided by: Kris Much confusion caused by (races in): md(4) [1] You are not supposed to understand anything past this point. [2] This line should simplify life for the peanut gallery.
* Retire unused dev_named() function.phk2005-09-151-13/+0
|
* Properly un-giant-trick the cdevsw in fini_cdevsw()phk2005-08-201-3/+7
| | | | Tripped over by: Huang wen hui <huang@gddsn.org.cn>
* Handle device drivers with D_NEEDGIANT in a way which does notphk2005-08-171-9/+155
| | | | | penalize the 'good' drivers: Allocate a shadow cdevsw and populate it with wrapper functions which grab Giant
* Remove stale comment.phk2005-08-161-2/+0
|
* Create a new internal .h file to communicate very private stuffphk2005-08-161-0/+2
| | | | | | from kern_conf.c to devfs. For now just two prototypes, more to come.
* When devfs cloning takes place, provide access to the credential of therwatson2005-07-141-5/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | process that caused the clone event to take place for the device driver creating the device. This allows cloned device drivers to adapt the device node based on security aspects of the process, such as the uid, gid, and MAC label. - Add a cred reference to struct cdev, so that when a device node is instantiated as a vnode, the cloning credential can be exposed to MAC. - Add make_dev_cred(), a version of make_dev() that additionally accepts the credential to stick in the struct cdev. Implement it and make_dev() in terms of a back-end make_dev_credv(). - Add a new event handler, dev_clone_cred, which can be registered to receive the credential instead of dev_clone, if desired. - Modify the MAC entry point mac_create_devfs_device() to accept an optional credential pointer (may be NULL), so that MAC policies can inspect and act on the label or other elements of the credential when initializing the skeleton device protections. - Modify tty_pty.c to register clone_dev_cred and invoke make_dev_cred(), so that the pty clone credential is exposed to the MAC Framework. While currently primarily focussed on MAC policies, this change is also a prerequisite for changes to allow ptys to be instantiated with the UID of the process looking up the pty. This requires further changes to the pty driver -- in particular, to immediately recycle pty nodes on last close so that the credential-related state can be recreated on next lookup. Submitted by: Andrew Reisse <andrew.reisse@sparta.com> Obtained from: TrustedBSD Project Sponsored by: SPAWAR, SPARTA MFC after: 1 week MFC note: Merge to 6.x, but not 5.x for ABI reasons
* cdev (still) needs per instance uid/gid/modephk2005-03-311-9/+15
| | | | | | Add unlocked version of dev_ref() Clean up various stuff in sys/conf.h
* Rename dev_ref() to dev_refl()phk2005-03-311-1/+1
|
* Remove the global cdev hash and use the cdevsw list instead.phk2005-03-291-29/+2
| | | | | | | | Don't remove the now unused element from cdev yet, wait until we have a better reason to bump the version. There is now no longer any upper limit on how many device drivers a FreeBSD kernel can have.
* Remove the global cdev hash and use the cdevsw list instead.phk2005-03-291-37/+9
| | | | | Don't remove the now unused element from cdev yet, wait until we have a better reason to bump the version.
* Privatize major().phk2005-03-291-1/+1
|
* Kill MAJOR_AUTOphk2005-03-171-3/+3
|
* Prepare for the final onslaught on devices:phk2005-03-171-5/+9
| | | | | | | | Move uid/gid/mode from cdev to cdevsw. Add kind field to use for devd(8) later. Bump both D_VERSION and __FreeBSD_version
* Remove findcdev().phk2005-03-151-19/+0
|
* Rename cdev->si_udev to cdev->si_drv0 to reflect the new nature ofphk2005-03-151-6/+6
| | | | the field.
* Try to fix the mess I made of devname, with the minimal subset of thephk2005-03-101-35/+0
| | | | larger minor/major patch which was posted for testing.
* Fix signedness of minor2unit().phk2005-03-081-4/+4
|
* Also handle d_maj hints from cloning drivers correctly.phk2005-02-271-8/+9
|
* Whine about any drivers which hardcode the device major number.phk2005-02-271-11/+5
|
* Use dynamic major number allocation for /dev/console, there is nophk2005-02-271-4/+1
| | | | | | | longer any benefit from hard wiring it. Remove special hack used to wire major to zero despite zero having a different magic meaning as well.
* Reap more benefits from DEVFS:phk2005-02-221-13/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | List devfs_dirents rather than vnodes off their shared struct cdev, this saves a pointer field in the vnode at the expense of a field in the devfs_dirent. There are often 100 times more vnodes so this is bargain. In addition it makes it harder for people to try to do stypid things like "finding the vnode from cdev". Since DEVFS handles all VCHR nodes now, we can do the vnode related cleanup in devfs_reclaim() instead of in dev_rel() and vgonel(). Similarly, we can do the struct cdev related cleanup in dev_rel() instead of devfs_reclaim(). rename idestroy_dev() to destroy_devl() for consistency. Add LIST_ENTRY de_alias to struct devfs_dirent. Remove v_specnext from struct vnode. Change si_hlist to si_alist in struct cdev. String new devfs vnodes' devfs_dirent on si_alist when we create them and take them off in devfs_reclaim(). Fix devfs_revoke() accordingly. Also don't clear fields devfs_reclaim() will clear when called from vgone(); Let devfs_reclaim() call dev_rel() instead of vgonel(). Move the usecount tracking from dev_rel() to devfs_reclaim(), and let dev_rel() take a struct cdev argument instead of vnode. Destroy SI_CHEAPCLONE devices in dev_rel() (instead of devfs_reclaim()) when they are no longer used. (This should maybe happen in devfs_close() instead.)
* Make dev_ref() require the dev_lock() to be held and use it fromphk2005-02-221-2/+1
| | | | devfs instead of directly frobbing the si_refcount.
* Use MAXMINORphk2005-01-291-5/+5
|
OpenPOWER on IntegriCloud