summaryrefslogtreecommitdiffstats
path: root/sys/kern/tty.c
diff options
context:
space:
mode:
authorsf <sf@openbsd.org>2015-07-20 22:28:57 +0000
committersf <sf@openbsd.org>2015-07-20 22:28:57 +0000
commit47ac5982efe8335c499b6750c749e7a54d4fe336 (patch)
tree492cbc4d2d4b3e91fdc25936c895b983e7b8e744 /sys/kern/tty.c
parentImplemented MPLS pseudowire (mpw(4)) to be used with VPLS and VPWS. (diff)
downloadwireguard-openbsd-47ac5982efe8335c499b6750c749e7a54d4fe336.tar.xz
wireguard-openbsd-47ac5982efe8335c499b6750c749e7a54d4fe336.zip
Fix tty hiwat handling a bit
- Introduce new defines TTHIWATMINSPACE, TTMINHIWAT for some magic values that are used in tty.c. - Remove hiwat adjustments in ttwrite(). This fixes this codepath not being interrupt safe. - Change ttysetwater() to keep at least TTHIWATMINSPACE space above the high water mark. This makes it consistent with ttycheckoutq(). Without this change, the hiwat adjustment change above causes deadlocks in pty. ok kspillner@ commit it now deraadt@
Diffstat (limited to 'sys/kern/tty.c')
-rw-r--r--sys/kern/tty.c19
1 files changed, 5 insertions, 14 deletions
diff --git a/sys/kern/tty.c b/sys/kern/tty.c
index c0ec4f0e259..354d14d52d2 100644
--- a/sys/kern/tty.c
+++ b/sys/kern/tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.c,v 1.121 2015/02/10 21:56:10 miod Exp $ */
+/* $OpenBSD: tty.c,v 1.122 2015/07/20 22:28:57 sf Exp $ */
/* $NetBSD: tty.c,v 1.68.4.2 1996/06/06 16:04:52 thorpej Exp $ */
/*-
@@ -1688,7 +1688,7 @@ ttycheckoutq(struct tty *tp, int wait)
hiwat = tp->t_hiwat;
s = spltty();
oldsig = wait ? curproc->p_siglist : 0;
- if (tp->t_outq.c_cc > hiwat + 200)
+ if (tp->t_outq.c_cc > hiwat + TTHIWATMINSPACE)
while (tp->t_outq.c_cc > hiwat) {
ttstart(tp);
if (wait == 0 || curproc->p_siglist != oldsig) {
@@ -1823,7 +1823,7 @@ loop:
tp->t_rocount = 0;
if (ttyoutput(*cp, tp) >= 0) {
/* out of space */
- goto overfull;
+ goto ovhiwat;
}
cp++;
cc--;
@@ -1849,7 +1849,7 @@ loop:
tp->t_outcc += ce;
if (i > 0) {
/* out of space */
- goto overfull;
+ goto ovhiwat;
}
if (ISSET(tp->t_lflag, FLUSHO) ||
tp->t_outq.c_cc > hiwat)
@@ -1869,15 +1869,6 @@ done:
explicit_bzero(obuf, obufcc);
return (error);
-overfull:
- /*
- * Since we are using ring buffers, if we can't insert any more into
- * the output queue, we can assume the ring is full and that someone
- * forgot to set the high water mark correctly. We set it and then
- * proceed as normal.
- */
- hiwat = tp->t_outq.c_cc - 1;
-
ovhiwat:
ttstart(tp);
s = spltty();
@@ -2114,7 +2105,7 @@ ttsetwater(struct tty *tp)
cps = tp->t_ospeed / 10;
tp->t_lowat = x = CLAMP(cps / 2, TTMAXLOWAT, TTMINLOWAT);
x += cps;
- tp->t_hiwat = CLAMP(x, tp->t_outq.c_cn, 100);
+ tp->t_hiwat = CLAMP(x, tp->t_outq.c_cn - TTHIWATMINSPACE, TTMINHIWAT);
#undef CLAMP
}