summaryrefslogtreecommitdiffstats
path: root/sys/kern/tty.c
Commit message (Collapse)AuthorAgeFilesLines
* Use the proper flag to let kern.ttys be executed without Giant.ed2009-01-261-1/+1
| | | | Pointed out by: jhb
* Mark kern.ttys as MPSAFE.ed2009-01-241-1/+1
| | | | | sysctl now allows Giantless calls, so make kern.ttys use this. If it needs Giant, it locks the proper TTY anyway.
* Fix a corner case in my previous commit.ed2009-01-021-1/+2
| | | | | Even though there are not many setups that have absolutely no console device, make sure a close() on a TTY doesn't dereference a null pointer.
* Don't let /dev/console be revoked if the TTY below is being closed.ed2009-01-021-0/+7
| | | | | | | | | | | During startup some of the syscons TTY's are used to set attributes like the screensaver and mouse options. These actions cause /dev/console to be rendered unusable. Fix the issue by leaving the TTY opened when it is used as the console device. Reported by: imp
* Let wchan names more closely match pre-MPSAFE TTY behaviour.ed2008-12-201-3/+3
| | | | | | | | | Right now the wchan strings "ttyinp" and "ttybgw" only differ one character from the strings we used prior to MPSAFE TTY. Just rename them back to their pre-MPSAFE TTY counterparts. Also rename "ttylck" to "ttymtx", which should make it more clear that a process is blocked on the TTY mutex, not some other form of locking.
* Further beautify the lock strings to be more pleasing to the eye andivoras2008-12-191-4/+4
| | | | | | | self documenting within 6 characters. Reviewed by: ed (older version) Approved by: gnn (older version)
* Remove spaces in wait object names to make top (1) output prettier andivoras2008-12-181-5/+5
| | | | | | | unbreak scripts that examine ps (1) output. Reviewed by: ed Approved by: gnn (mentor)
* Change ttyhook_register() second argument from thread to process pointer.mav2008-12-131-4/+11
| | | | | Thread was not really needed there, while previous ng_tty implementation that used thread pointer had locking issues (using sx while holding mutex).
* Reduce the default baud rate of PTY's to 9600.ed2008-11-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | On RELENG_6 (and probably RELENG_7) we see our syscons windows and pseudo-terminals have the following buffer sizes: | LINE RAW CAN OUT IHIWT ILOWT OHWT LWT COL STATE SESS PGID DISC | ttyv0 0 0 0 7680 6720 2052 256 7 OCcl 1146 1146 term | ttyp0 0 0 0 7680 6720 1296 256 0 OCc 82033 82033 term These buffer sizes make no sense, because we often have much more output than input, but I guess having higher input buffer sizes improves guarantees of the system. On MPSAFE TTY I just sent both the input and output buffer sizes to 7 KB, which is pretty big on a standard FreeBSD install with 8 syscons windows and some PTY's. Reduce the baud rate to 9600 baud, which means we now have the following buffer sizes: | LINE INQ CAN LIN LOW OUTQ USE LOW COL SESS PGID STATE | ttyv0 1920 0 0 192 1984 0 199 7 2401 2401 Oil | pts/0 1920 0 0 192 1984 0 199 5631 1305 2526 Oi This is a lot smaller, but for pseudo-devices this should be good enough. You need to do a lot of punching to fill up a 7.5 KB input buffer. If it turns out things don't work out this way, we'll just switch to 19200 baud.
* Clamp the values of t_column to 5 digits in `pstat -t' and `show all ttys'.ed2008-11-011-1/+1
| | | | | | | | We often run into these very high column numbers when we run curses applications, because they don't print any newlines. This messes up the table output of `pstat -t'. If these numbers get really high, they aren't of any use to the reader anyway. Convert them to `99999' when they run out of bounds.
* Reimplement the /dev/console device node.ed2008-11-011-9/+87
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | One of the pieces of code that I had left alone during the development of the MPSAFE TTY layer, was tty_cons.c. This file actually has two different functions: - It contains low-level console input/output routines (cnputc(), etc). - It creates /dev/console and wraps all its cdevsw calls to the appropriate TTY. This commit reimplements the second set of functions by moving it directly into the TTY layer. /dev/console is now a character device node that's basically a regular TTY, but does a lookup of `si_drv1' each time you open it. d_write has also been changed to call log_console(). d_close() is not present, because we must make sure we don't revoke the TTY after writing a log message to it. Even though I'm not convinced this is in line with the future directions of our console code, it is a good move for now. It removes recursive locking from the top half of the TTY layer. The previous implementation called into the TTY layer with Giant held. I'm renaming tty_cons.c to kern_cons.c now. The code hardly contains any TTY related bits, so we'd better give it a less misleading name. Tested by: Andrzej Tobola <ato iem pw edu pl>, Carlos A.M. dos Santos <unixmania gmail com>, Eygene Ryabinkin <rea-fbsd codelabs ru>
* Fix spelling mistake in the last rev.thompsa2008-10-211-1/+1
|
* If we have getc_inject hooked then the outq buffer is inaccessible to thethompsa2008-10-211-0/+4
| | | | | | driver so skip the drain rather than waiting indefinitely. Reviewed by: ed
* Import some improvements to the TTY code from the MPSAFE TTY branch.ed2008-10-151-37/+162
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Change the ddb(4) commands to be more useful (by thompsa@): - `show ttys' is now called `show all ttys'. This command will now also display the address where the TTY data structure resides. - Add `show tty <addr>', which dumps the TTY in a readable form. - Place an upper bound on the TTY buffer sizes. Some drivers do not want to care about baud rates. Protect these drivers by preventing the TTY buffers from getting enormous. Right now we'll just clamp it to 64K, which is pretty high, taking into account that these buffers are only used by the built-in discipline. - Only call ttydev_leave() when needed. Back in April/May the TTY reference counting mechanism was a little different, which required us to call ttydev_leave() each time we finished a cdev operation. Nowadays we only need to call ttydev_leave() when we really mark it as being closed. - Improve return codes of read() and write() on TTY device nodes. - Make sure we really wake up all blocked threads when the driver calls tty_rel_gone(). There were some possible code paths where we didn't properly wake up any readers/writers. - Add extra assertions to prevent sleeping on a TTY that has been abandoned by the driver. - Use ttydev_cdevsw as a more reliable method to figure out whether a device node is a real TTY device node. Obtained from: //depot/projects/mpsafetty/... Reviewed by: thompsa
* Don't forget to initialize `int error' in ttydev_open().ed2008-09-261-1/+1
| | | | | | | | | | I've had some reports in the past that opening an already opened TTY through, for example, /dev/tty can fail with random error codes. Looking at ttydev_open(), I can see there is a way `error' is returned without initialising it. Even though I haven't had any confirmation this fixes the bug, I'll fix it anyway. Reported by: Andrzej Tobola <ato iem pw edu pl>
* Fix a crash when calling tty_rel_free() while draining during closure.ed2008-09-241-2/+2
| | | | | | | | | | | | Yesterday I got two reports of potential crashes, related to TTY deallocation during device closure. When a thread is in TF_OPENCLOSE, draining its output upon closure, we should not allow calls to tty_rel_free() to happen at the same time. This could cause the TTY to be torn down twice. PR: kern/127561 Reported by: KOIE Hidetaka <koie suri co jp> Discussed with: thompsa
* Introduce a hooks layer for the MPSAFE TTY layer.ed2008-09-221-2/+88
| | | | | | | | | | | | | | | | | | | | One of the features that prevented us from fixing some of the TTY consumers to work once again, was an interface that allowed consumers to do the following: - `Sniff' incoming data, which is used by the snp(4) driver. - Take direct control of the input and output paths of a TTY, which is used by ng_tty(4), ppp(4), sl(4), etc. There's no practical advantage in committing a hooks layer without having any consumers. In P4 there is a preliminary port of snp(4) and thompsa@ is busy porting ng_tty(4) to this interface. I already want to have it in the tree, because this may stimulate others to work on the remaining modules. Discussed with: thompsa Obtained from: //depot/projects/mpsafetty/...
* Fix minor TTY API inconsistency.ed2008-09-161-0/+3
| | | | | | | | | | Unlike tty_rel_gone() and tty_rel_sess(), the tty_rel_pgrp() routine does not unlock the TTY. I once had the idea to make the code call tty_rel_pgrp() and tty_rel_sess(), picking up the TTY lock once. This turned out a little harder than I expected, so this is how it works now. It's a lot easier if we just let tty_rel_pgrp() unlock the TTY, because the other routines do this anyway.
* Make TIOCCONS use priv_check() instead of checking /dev/console permissions.ed2008-09-061-35/+8
| | | | | | | | | | | | | As discussed with Robert on IRC, checking the permissions on /dev/console to see if we can call TIOCCONS could be unreliable. When we run a chroot() without a devfs instance mounted inside, it won't actually check the permissions on the device node inside the devfs instance. Using the already existing PRIV_TTY_CONSOLE for this seems like a better idea. Approved by: rwatson
* Implement pts(4) packet mode.ed2008-09-041-0/+21
| | | | | | | | | As reported by several users on the mailing lists, applications like screen(1) fail to properly handle ^S and ^Q characters. This was because MPSAFE TTY didn't implement packet mode (TIOCPKT) yet. Add basic packet mode support to make these applications work again. Obtained from: //depot/projects/mpsafetty/...
* Fix some edge cases in the TTY queues:ed2008-08-301-22/+10
| | | | | | | | | | | | | | | | | | | | | | | | - In the current design, when a TTY decreases its baud rate, it tries to shrink the queues. This may not always be possible, because it will not free any blocks that are still filled with data. Change the TTY queues to store a `quota' value as well, which means it will not free any blocks when changing the baud rate, but when placing blocks back into the queue. When the amount of blocks exceeds the quota, they get freed. It also fixes some edge cases, where TIOCSETA during read()/ write()-calls could actually make the queue a tiny bit bigger than in normal cases. - Don't leak blocks of memory when calling TIOCSETA when the device driver abandons the TTY while allocating memory. - Create ttyoutq_init() and ttyinq_init() to initialize the queues, instead of initializing them by hand. The new TTY snoop driver also creates an outq, so it's good to have a proper interface to do this. Obtained from: //depot/projects/mpsafetty/...
* Properly unlock the init/lock-state devices when invoking TIOCSETA.ed2008-08-271-1/+0
| | | | | | | | For some reason a return-statement crept into this code, where it shouldn't belong. This means we didn't properly unlock the TTY before returning to userspace. Submitted by: Tor Egge <tor egge cvsup no freebsd org>
* Fix two small bugs in tcsetattr().ed2008-08-221-7/+6
| | | | | | | | | | | | | | | | | | - According to POSIX, tcsetattr() must not fail when any of the bits in the structure are unsupported, but it must leave the unsupported flags alone. - The CIGNORE flag (set by TCSASOFT, extension) was not cleared from c_cflag, which means using it would cause it to be applied during its entire lifespan. Eventually make sure we clear the flag. I don't really like CIGNORE, but I think we must keep it alive right now. With our new TTY layer, we don't actually need this mechanism, because if you leave c_cflag, c_ispeed and c_ospeed alone, we won't make a call into the device driver anyway. Reported by: naddy Tested by: naddy
* Prevent VSTART flooding when turning on software flow control.ed2008-08-221-1/+1
| | | | | | | | It turned out we transmitted VSTART after each successful read on a TTY when software flow control was turned on. This was because of a very evil bug where we tested the TF_HIWAT_IN flag the other way around. Reported by: Christian Weisgerber <naddy mips inka de>
* Integrate the new MPSAFE TTY layer to the FreeBSD operating system.ed2008-08-201-2830/+1352
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The last half year I've been working on a replacement TTY layer for the FreeBSD kernel. The new TTY layer was designed to improve the following: - Improved driver model: The old TTY layer has a driver model that is not abstract enough to make it friendly to use. A good example is the output path, where the device drivers directly access the output buffers. This means that an in-kernel PPP implementation must always convert network buffers into TTY buffers. If a PPP implementation would be built on top of the new TTY layer (still needs a hooks layer, though), it would allow the PPP implementation to directly hand the data to the TTY driver. - Improved hotplugging: With the old TTY layer, it isn't entirely safe to destroy TTY's from the system. This implementation has a two-step destructing design, where the driver first abandons the TTY. After all threads have left the TTY, the TTY layer calls a routine in the driver, which can be used to free resources (unit numbers, etc). The pts(4) driver also implements this feature, which means posix_openpt() will now return PTY's that are created on the fly. - Improved performance: One of the major improvements is the per-TTY mutex, which is expected to improve scalability when compared to the old Giant locking. Another change is the unbuffered copying to userspace, which is both used on TTY device nodes and PTY masters. Upgrading should be quite straightforward. Unlike previous versions, existing kernel configuration files do not need to be changed, except when they reference device drivers that are listed in UPDATING. Obtained from: //depot/projects/mpsafetty/... Approved by: philip (ex-mentor) Discussed: on the lists, at BSDCan, at the DevSummit Sponsored by: Snow B.V., the Netherlands dcons(4) fixed by: kan
* Move ttyinfo() into its own C file.ed2008-07-251-269/+0
| | | | | | | | | | | | The ttyinfo() routine generates the fancy output when pressing ^T. Right now it is stored in tty.c. In the MPSAFE TTY code it is already stored in tty_info.c. To make integration of the MPSAFE TTY code a little easier, take the same approach. This makes the TTY code a little bit more readable, because having the proc_*/thread_* routines in tty.c is very distractful. Approved by: philip (mentor)
* Rev. 1.274 put the ttyrel() call before the destroy_dev() in thekib2008-05-231-2/+5
| | | | | | | | | | | | | | ttyfree(), freeing the tty. Since destroy_dev() may call d_purge() cdevsw method, that is the ttypurge() for the tty, the code ends up accessing freed tty structure. Put the ttyrel() after destroy_dev() in the ttyfree. To prevent the panic the rev. 1.274 provided fix for, check the TS_GONE in sysctl handler and refuse to provide information on such tty. Reported, debugging help and tested by: pho DIscussed with and reviewed by: jhb MFC after: 1 week
* The dev_refthread() in the tty_gettp() may fail, because Giant is takenkib2008-05-231-5/+6
| | | | | | | | | | | | | | | in the giant_trick routines after the dev_refthread increments the si_threadcount. Remove assert, do not perform dev_relthread() for failed dev_refthread(), and handle failure in the tty_gettp() callers (cdevsw tty methods). Before kern_conf.c 1.210 and 1.211, the kernel usually paniced in the giant_trick routines dereferencing NULL cdevsw, not taking this fault. Reported by: Vince Hoffman <jhary unsane co uk> Debugging help and tested by: pho Reviewed by: jhb MFC after: 1 week
* Use the t_state for the TS_GONE test.kib2008-05-231-1/+1
| | | | | Submitted by: jhb MFC after: 3 days
* Move TTY unrelated bits out of <sys/tty.h>.ed2008-05-231-0/+1
| | | | | | | | | | | | | | | | For some reason, the <sys/tty.h> header file also contains routines of the clists and console that are used inside the TTY layer. Because the clists are not only used by the TTY layer (example: various input drivers), we'd better move the entire clist programming interface into <sys/clist.h>. Also remove a declaration of nonexistent variable. The <sys/tty.h> header also contains various definitions for the console code (tty_cons.c). Also move these to <sys/cons.h>, because they are not implemented inside the TTY layer. While there, create separate malloc pools for the clist and console code. Approved by: philip (mentor)
* Implement POSIX function tcgetsid() which returns session id.davidxu2008-04-151-0/+5
| | | | PR: stand/107561
* - Relax requirements for p_numthreads, p_threads, p_swtick, and p_nice fromjeff2008-03-191-6/+6
| | | | | | | requiring the per-process spinlock to only requiring the process lock. - Reflect these changes in the proc.h documentation and consumers throughout the kernel. This is a substantial reduction in locking cost for these fields and was made possible by recent changes to threading support.
* Close a race in the kern.ttys sysctl handler that resulted in panics injhb2008-01-081-3/+20
| | | | | | | | | | | | | | | | | | | | | | | | dev2udev() when a tty was being detached concurrently with the sysctl handler: - Hold the 'tty_list_mutex' lock while we read all the fields out of the struct tty for copying out later. Previously the pty(4) and pts(4) destroy routines could set t_dev to NULL, drop their reference on the tty and destroy the cdev while the sysctl handler was attempting to invoke dev2udev() on the cdev being destroyed. This happened when the sysctl handler read the value of t_dev prior to it being set to NULL either due to it being stale or due to timing races. By holding the list lock we guarantee that the destroy routines will block in ttyrel() in that case and not destroy the cdev until after we've copied all of our data. We may see a NULL cdev pointer or we may see the previous value, but the previous value will no longer point to a destroyed cdev if we see it. - Fix the ttyfree() routine used by tty device drivers in their detach methods to use ttyrel() on the tty so we don't leak them. Also, fix it to use the same order of operations as pty/pts destruction (set t_dev NULL, ttyrel(), destroy_dev()) so it cooperates with the sysctl handler. MFC after: 3 days Tested by: avatar
* ttyfree() frees the cdev(). But if there are pending kevents,kib2007-07-201-7/+17
| | | | | | | | | | | | | | | | filt_ttyrdetach() etc would later attempt to dereference cdev->si_tty, causing a 0xdeadc0de dereference. Change kn_hook value from cdev to struct tty to avoid dereferencing freed cdev. In ttygone(), wake up select(), sigio and kevent() users in addition to the queue sleepers. Return EV_EOF from kevent filters if TS_GONE is set. Submitted by: peter Tested by: Peter Holm Approved by: re (kensmith) MFC after: 2 weeks
* - Use rufetchcalc() rather than calcru() in ttyinfo so that we getjeff2007-07-011-3/+2
| | | | | | | | correct system and user time stats. Approved by: re Reported by: kris Discussed with: Attilio
* Re-acquire the PROC_SLOCK before calling calcru(), and release it after,cognet2007-06-111-0/+2
| | | | | | since calcru() expects it to be locked. Reviewed by: attilio
* The new compiler can't quite follow the logic of has_stime andmjacob2007-06-101-1/+1
| | | | complains about using uninitialized tags in stime.
* Commit 9/14 of sched_lock decomposition.jeff2007-06-041-57/+117
| | | | | | | | | | - Attempt to return the ttyinfo() selection algorithm to something sane as it has been broken and disabled for some time. Adapt this algorithm in such a way that it does not conflict with per-cpu scheduler locking. Tested by: kris, current@ Tested on: i386, amd64, ULE, 4BSD, libthr, libkse, PREEMPTION, etc. Discussed with: kris, attilio, kmacy, jhb, julian, bde (small parts each)
* Back out rev. 1.266. The real cause for the recent panics has been fixedmbr2006-12-201-1/+1
| | | | in rev. 1.267 and there is no need to keep this test.
* Giant might have been temporarily dropped while waiting for proctree_lock, ↵mbr2006-12-191-1/+1
| | | | | | | | | allowing for an intervening tty_close() that cleared tp->t_session. Submitted by: tegge MFC: 1 day
* Add the tp->t_refcnt validity check back. There are still some racembr2006-12-191-1/+1
| | | | conditions where tp->t_refcnt can go to zero.
* Threading cleanup.. part 2 of several.julian2006-12-061-25/+2
| | | | | | | | | | | | | | | | | | | | | | Make part of John Birrell's KSE patch permanent.. Specifically, remove: Any reference of the ksegrp structure. This feature was never fully utilised and made things overly complicated. All code in the scheduler that tried to make threaded programs fair to unthreaded programs. Libpthread processes will already do this to some extent and libthr processes already disable it. Also: Since this makes such a big change to the scheduler(s), take the opportunity to rename some structures and elements that had to be moved anyhow. This makes the code a lot more readable. The ULE scheduler compiles again but I have no idea if it works. The 4bsd scheduler still reqires a little cleaning and some functions that now do ALMOST nothing will go away, but I thought I'd do that as a separate commit. Tested by David Xu, and Dan Eischen using libthr and libpthread.
* Don't drop reference to tty in tty_close() if TS_ISOPEN is already cleared.tegge2006-11-061-7/+6
| | | | Reviewed by: bde
* Sweep kernel replacing suser(9) calls with priv(9) calls, assigningrwatson2006-11-061-6/+8
| | | | | | | | | | | | | specific privilege names to a broad range of privileges. These may require some future tweaking. Sponsored by: nCircle Network Security, Inc. Obtained from: TrustedBSD Project Discussed on: arch@ Reviewed (at least in part) by: mlaier, jmg, pjd, bde, ceri, Alex Lyashkov <umka at sevcity dot net>, Skip Ford <skip dot ford at verizon dot net>, Antoine Brodin <antoine dot brodin at laposte dot net>
* Make KSE a kernel option, turned on by default in all GENERICjb2006-10-261-0/+11
| | | | | | | kernel configs except sun4v (which doesn't process signals properly with KSE). Reviewed by: davidxu@
* Any call of tty_close() with a tty refcount of <= 1 is wrong and we willmbr2006-09-301-6/+9
| | | | | | | free the tty in this case. This is a workaround until the underlaying devfs/tty problems are fixed. MFC after: 1 day
* Check for tp->t_refcnt == 0 before doing anything in tty_open().mbr2006-09-231-0/+6
| | | | | PR: 103520 MFC after: 1 week
* Back out rev. 1.258. The real race cause has been fixedmbr2006-09-211-2/+2
| | | | | | in rev. 1.241 of kern_proc.c. Requested by: jhb
* Fix locking race in ttymodem(). The locking of the proctree happens too latembr2006-09-101-2/+2
| | | | | | | | | | | | and opens a small race window before tp->t_session->s_leader is accessed. In case tp->t_session has just been set to NULL elsewhere, we get a panic(). This fix is a bandaid until someone else fixes the whole locking in the tty subsystem. Definitly more work needs to be done. MFC after: 1 week Reviewed by: mlaier PR: kern/103101
* Move the old BSD4.3 tty compatibility from (!BURN_BRIDGES && COMPAT_43)phk2006-01-101-11/+3
| | | | | | | | | | | | to COMPAT_43TTY. Add COMPAT_43TTY to NOTES and */conf/GENERIC Compile tty_compat.c only under the new option. Spit out #warning "Old BSD tty API used, please upgrade." if ioctl_compat.h gets #included from userland.
OpenPOWER on IntegriCloud