summaryrefslogtreecommitdiffstats
path: root/sys/compat/svr4
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2005-09-19 16:51:43 +0000
committerrwatson <rwatson@FreeBSD.org>2005-09-19 16:51:43 +0000
commitc479a90eb8129ad770ff6daba981e9f20af69e6f (patch)
treee3c313c0b77fbcc1f434ec162a95a06a9e05a773 /sys/compat/svr4
parent745da316335f104d267ad6c4b565be45311e5d6e (diff)
downloadFreeBSD-src-c479a90eb8129ad770ff6daba981e9f20af69e6f.zip
FreeBSD-src-c479a90eb8129ad770ff6daba981e9f20af69e6f.tar.gz
Add GIANT_REQUIRED and WITNESS sleep warnings to uprintf() and tprintf(),
as they both interact with the tty code (!MPSAFE) and may sleep if the tty buffer is full (per comment). Modify all consumers of uprintf() and tprintf() to hold Giant around calls into these functions. In most cases, this means adding an acquisition of Giant immediately around the function. In some cases (nfs_timer()), it means acquiring Giant higher up in the callout. With these changes, UFS no longer panics on SMP when either blocks are exhausted or inodes are exhausted under load due to races in the tty code when running without Giant. NB: Some reduction in calls to uprintf() in the svr4 code is probably desirable. NB: In the case of nfs_timer(), calling uprintf() while holding a mutex, or even in a callout at all, is a bad idea, and will generate warnings and potential upset. This needs to be fixed, but was a problem before this change. NB: uprintf()/tprintf() sleeping is generally a bad ideas, as is having non-MPSAFE tty code. MFC after: 1 week
Diffstat (limited to 'sys/compat/svr4')
-rw-r--r--sys/compat/svr4/svr4_fcntl.c6
-rw-r--r--sys/compat/svr4/svr4_ioctl.c2
-rw-r--r--sys/compat/svr4/svr4_ipc.c2
-rw-r--r--sys/compat/svr4/svr4_misc.c2
-rw-r--r--sys/compat/svr4/svr4_signal.c5
-rw-r--r--sys/compat/svr4/svr4_stat.c2
-rw-r--r--sys/compat/svr4/svr4_stream.c28
-rw-r--r--sys/compat/svr4/svr4_termios.c9
-rw-r--r--sys/compat/svr4/svr4_ttold.c24
-rw-r--r--sys/compat/svr4/svr4_util.h5
10 files changed, 79 insertions, 6 deletions
diff --git a/sys/compat/svr4/svr4_fcntl.c b/sys/compat/svr4/svr4_fcntl.c
index ad74838..2107813 100644
--- a/sys/compat/svr4/svr4_fcntl.c
+++ b/sys/compat/svr4/svr4_fcntl.c
@@ -377,8 +377,10 @@ svr4_sys_open(td, uap)
free(newpath, M_TEMP);
if (error) {
- /* uprintf("svr4_open(%s, 0x%0x, 0%o): %d\n", uap->path,
- uap->flags, uap->mode, error);*/
+ /* mtx_lock(&Giant);
+ uprintf("svr4_open(%s, 0x%0x, 0%o): %d\n", uap->path,
+ uap->flags, uap->mode, error);
+ mtx_unlock(&Giant);*/
return error;
}
diff --git a/sys/compat/svr4/svr4_ioctl.c b/sys/compat/svr4/svr4_ioctl.c
index b192a2c..ba8218f 100644
--- a/sys/compat/svr4/svr4_ioctl.c
+++ b/sys/compat/svr4/svr4_ioctl.c
@@ -30,6 +30,8 @@
__FBSDID("$FreeBSD$");
#include <sys/param.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/file.h>
#include <sys/filedesc.h>
diff --git a/sys/compat/svr4/svr4_ipc.c b/sys/compat/svr4/svr4_ipc.c
index 0b6acbf..976668c 100644
--- a/sys/compat/svr4/svr4_ipc.c
+++ b/sys/compat/svr4/svr4_ipc.c
@@ -77,7 +77,9 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/ipc.h>
+#include <sys/lock.h>
#include <sys/msg.h>
+#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/sem.h>
#include <sys/shm.h>
diff --git a/sys/compat/svr4/svr4_misc.c b/sys/compat/svr4/svr4_misc.c
index d7a9069..2b31765 100644
--- a/sys/compat/svr4/svr4_misc.c
+++ b/sys/compat/svr4/svr4_misc.c
@@ -485,7 +485,9 @@ again:
panic("svr4_sys_getdents64: bad reclen");
off = *cookie++; /* each entry points to the next */
if ((off >> 32) != 0) {
+ mtx_lock(&Giant);
uprintf("svr4_sys_getdents64: dir offset too large for emulated program");
+ mtx_unlock(&Giant);
error = EINVAL;
goto out;
}
diff --git a/sys/compat/svr4/svr4_signal.c b/sys/compat/svr4/svr4_signal.c
index c0a3a21..57023e9 100644
--- a/sys/compat/svr4/svr4_signal.c
+++ b/sys/compat/svr4/svr4_signal.c
@@ -238,8 +238,11 @@ svr4_to_bsd_sigaltstack(sss, bss)
bss->ss_flags |= SS_DISABLE;
if ((sss->ss_flags & SVR4_SS_ONSTACK) != 0)
bss->ss_flags |= SS_ONSTACK;
- if ((sss->ss_flags & ~SVR4_SS_ALLBITS) != 0)
+ if ((sss->ss_flags & ~SVR4_SS_ALLBITS) != 0) {
+ mtx_lock(&Giant);
/*XXX*/ uprintf("svr4_to_bsd_sigaltstack: extra bits ignored\n");
+ mtx_unlock(&Giant);
+ }
}
void
diff --git a/sys/compat/svr4/svr4_stat.c b/sys/compat/svr4/svr4_stat.c
index d0f4d93..62bc223 100644
--- a/sys/compat/svr4/svr4_stat.c
+++ b/sys/compat/svr4/svr4_stat.c
@@ -30,6 +30,8 @@
__FBSDID("$FreeBSD$");
#include <sys/param.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/stat.h>
diff --git a/sys/compat/svr4/svr4_stream.c b/sys/compat/svr4/svr4_stream.c
index bd6fa5a..a8153e9 100644
--- a/sys/compat/svr4/svr4_stream.c
+++ b/sys/compat/svr4/svr4_stream.c
@@ -378,6 +378,8 @@ bufprint(buf, len)
{
size_t i;
+ GIANT_REQUIRED;
+
uprintf("\n\t");
for (i = 0; i < len; i++) {
uprintf("%x ", buf[i]);
@@ -395,6 +397,8 @@ show_ioc(str, ioc)
int len;
int error;
+ GIANT_REQUIRED;
+
len = ioc->len;
if (len > 1024)
len = 1024;
@@ -430,6 +434,8 @@ show_strbuf(str)
int maxlen = str->maxlen;
int len = str->len;
+ GIANT_REQUIRED;
+
if (maxlen > 8192)
maxlen = 8192;
@@ -473,6 +479,8 @@ show_msg(str, fd, ctl, dat, flags)
struct svr4_strbuf buf;
int error;
+ GIANT_REQUIRED;
+
uprintf("%s(%d", str, fd);
if (ctl != NULL) {
if ((error = copyin(ctl, &buf, sizeof(buf))) != 0)
@@ -1407,8 +1415,12 @@ i_str(fp, td, retval, fd, cmd, dat)
return error;
#ifdef DEBUG_SVR4
- if ((error = show_ioc(">", &ioc)) != 0)
+ mtx_lock(&Giant);
+ if ((error = show_ioc(">", &ioc)) != 0) {
+ mtx_unlock(&Giant);
return error;
+ }
+ mtx_unlock(&Giant);
#endif /* DEBUG_SVR4 */
switch (ioc.cmd & 0xff00) {
@@ -1429,8 +1441,12 @@ i_str(fp, td, retval, fd, cmd, dat)
}
#ifdef DEBUG_SVR4
- if ((error = show_ioc("<", &ioc)) != 0)
+ mtx_lock(&Giant);
+ if ((error = show_ioc("<", &ioc)) != 0) {
+ mtx_lock(&Giant);
return error;
+ }
+ mtx_unlock(&Giant);
#endif /* DEBUG_SVR4 */
return copyout(&ioc, dat, sizeof(ioc));
}
@@ -1550,7 +1566,9 @@ svr4_stream_ioctl(fp, td, retval, fd, cmd, dat)
case SVR4_I_PUSH:
DPRINTF(("I_PUSH %p\n", dat));
#if defined(DEBUG_SVR4)
+ mtx_lock(&Giant);
show_strbuf((struct svr4_strbuf *)dat);
+ mtx_unlock(&Giant);
#endif
return 0;
@@ -1743,8 +1761,10 @@ svr4_do_putmsg(td, uap, fp)
retval = td->td_retval;
#ifdef DEBUG_SVR4
+ mtx_lock(&Giant);
show_msg(">putmsg", uap->fd, uap->ctl,
uap->dat, uap->flags);
+ mtx_unlock(&Giant);
#endif /* DEBUG_SVR4 */
FILE_LOCK_ASSERT(fp, MA_NOTOWNED);
@@ -1940,8 +1960,10 @@ svr4_do_getmsg(td, uap, fp)
memset(&sc, 0, sizeof(sc));
#ifdef DEBUG_SVR4
+ mtx_lock(&Giant);
show_msg(">getmsg", uap->fd, uap->ctl,
uap->dat, 0);
+ mtx_unlock(&Giant);
#endif /* DEBUG_SVR4 */
if (uap->ctl != NULL) {
@@ -2249,8 +2271,10 @@ svr4_do_getmsg(td, uap, fp)
*retval = 0;
#ifdef DEBUG_SVR4
+ mtx_lock(&Giant);
show_msg("<getmsg", uap->fd, uap->ctl,
uap->dat, fl);
+ mtx_unlock(&Giant);
#endif /* DEBUG_SVR4 */
return error;
}
diff --git a/sys/compat/svr4/svr4_termios.c b/sys/compat/svr4/svr4_termios.c
index 37a6783..b204929 100644
--- a/sys/compat/svr4/svr4_termios.c
+++ b/sys/compat/svr4/svr4_termios.c
@@ -30,6 +30,8 @@
__FBSDID("$FreeBSD$");
#include <sys/param.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/systm.h>
#include <sys/file.h>
@@ -156,6 +158,9 @@ print_bsd_termios(bt)
const struct termios *bt;
{
int i;
+
+ GIANT_REQUIRED;
+
uprintf("BSD\niflag=%o oflag=%o cflag=%o lflag=%o\n",
bt->c_iflag, bt->c_oflag, bt->c_cflag, bt->c_lflag);
uprintf("cc: ");
@@ -508,7 +513,9 @@ svr4_term_ioctl(fp, td, retval, fd, cmd, data)
bsd_to_svr4_termios(&bt, &st);
#ifdef DEBUG_SVR4
+ mtx_lock(&Giant);
print_bsd_termios(&bt);
+ mtx_unlock(&Giant);
print_svr4_termios(&st);
#endif /* DEBUG_SVR4 */
@@ -576,7 +583,9 @@ svr4_term_ioctl(fp, td, retval, fd, cmd, data)
}
#ifdef DEBUG_SVR4
+ mtx_lock(&Giant);
print_bsd_termios(&bt);
+ mtx_unlock(&Giant);
print_svr4_termios(&st);
#endif /* DEBUG_SVR4 */
diff --git a/sys/compat/svr4/svr4_ttold.c b/sys/compat/svr4/svr4_ttold.c
index 3575607..537f88a 100644
--- a/sys/compat/svr4/svr4_ttold.c
+++ b/sys/compat/svr4/svr4_ttold.c
@@ -32,6 +32,8 @@ __FBSDID("$FreeBSD$");
#ifndef BURN_BRIDGES
#include <sys/param.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/systm.h>
#include <sys/file.h>
@@ -69,6 +71,8 @@ print_svr4_sgttyb(str, ss)
struct svr4_sgttyb *ss;
{
+ GIANT_REQUIRED;
+
uprintf("%s\nispeed=%o ospeed=%o ", str, ss->sg_ispeed, ss->sg_ospeed);
uprintf("erase=%o kill=%o flags=%o\n", ss->sg_erase, ss->sg_kill,
ss->sg_flags);
@@ -79,6 +83,9 @@ print_svr4_tchars(str, st)
const char *str;
struct svr4_tchars *st;
{
+
+ GIANT_REQUIRED;
+
uprintf("%s\nintrc=%o quitc=%o ", str, st->t_intrc, st->t_quitc);
uprintf("startc=%o stopc=%o eofc=%o brkc=%o\n", st->t_startc,
st->t_stopc, st->t_eofc, st->t_brkc);
@@ -89,6 +96,9 @@ print_svr4_ltchars(str, sl)
const char *str;
struct svr4_ltchars *sl;
{
+
+ GIANT_REQUIRED;
+
uprintf("%s\nsuspc=%o dsuspc=%o ", str, sl->t_suspc, sl->t_dsuspc);
uprintf("rprntc=%o flushc=%o werasc=%o lnextc=%o\n", sl->t_rprntc,
sl->t_flushc, sl->t_werasc, sl->t_lnextc);
@@ -231,7 +241,9 @@ svr4_ttold_ioctl(fp, td, retval, fd, cmd, data)
return copyout(&pid, data, sizeof(pid));
#else
+ mtx_lock(&Giant);
uprintf("ioctl(TIOCGSID) for pid %d unsupported\n", td->td_proc->p_pid);
+ mtx_unlock(&Giant);
return EINVAL;
#endif
}
@@ -248,7 +260,9 @@ svr4_ttold_ioctl(fp, td, retval, fd, cmd, data)
bsd_sgttyb_to_svr4_sgttyb(&bs, &ss);
#ifdef DEBUG_SVR4
+ mtx_lock(&Giant);
print_svr4_sgttyb("SVR4_TIOCGETP", &ss);
+ mtx_unlock(&Giant);
#endif /* DEBUG_SVR4 */
return copyout(&ss, data, sizeof(ss));
}
@@ -264,7 +278,9 @@ svr4_ttold_ioctl(fp, td, retval, fd, cmd, data)
svr4_sgttyb_to_bsd_sgttyb(&ss, &bs);
#ifdef DEBUG_SVR4
+ mtx_lock(&Giant);
print_svr4_sgttyb("SVR4_TIOCSET{P,N}", &ss);
+ mtx_unlock(&Giant);
#endif /* DEBUG_SVR4 */
cmd = (cmd == SVR4_TIOCSETP) ? TIOCSETP : TIOCSETN;
return fo_ioctl(fp, cmd, (caddr_t) &bs,
@@ -283,7 +299,9 @@ svr4_ttold_ioctl(fp, td, retval, fd, cmd, data)
bsd_tchars_to_svr4_tchars(&bt, &st);
#ifdef DEBUG_SVR4
+ mtx_lock(&Giant);
print_svr4_tchars("SVR4_TIOCGETC", &st);
+ mtx_unlock(&Giant);
#endif /* DEBUG_SVR4 */
return copyout(&st, data, sizeof(st));
}
@@ -298,7 +316,9 @@ svr4_ttold_ioctl(fp, td, retval, fd, cmd, data)
svr4_tchars_to_bsd_tchars(&st, &bt);
#ifdef DEBUG_SVR4
+ mtx_lock(&Giant);
print_svr4_tchars("SVR4_TIOCSETC", &st);
+ mtx_unlock(&Giant);
#endif /* DEBUG_SVR4 */
return fo_ioctl(fp, TIOCSETC, (caddr_t) &bt,
td->td_ucred, td);
@@ -316,7 +336,9 @@ svr4_ttold_ioctl(fp, td, retval, fd, cmd, data)
bsd_ltchars_to_svr4_ltchars(&bl, &sl);
#ifdef DEBUG_SVR4
+ mtx_lock(&Giant);
print_svr4_ltchars("SVR4_TIOCGLTC", &sl);
+ mtx_unlock(&Giant);
#endif /* DEBUG_SVR4 */
return copyout(&sl, data, sizeof(sl));
}
@@ -331,7 +353,9 @@ svr4_ttold_ioctl(fp, td, retval, fd, cmd, data)
svr4_ltchars_to_bsd_ltchars(&sl, &bl);
#ifdef DEBUG_SVR4
+ mtx_lock(&Giant);
print_svr4_ltchars("SVR4_TIOCSLTC", &sl);
+ mtx_unlock(&Giant);
#endif /* DEBUG_SVR4 */
return fo_ioctl(fp, TIOCSLTC, (caddr_t) &bl,
td->td_ucred, td);
diff --git a/sys/compat/svr4/svr4_util.h b/sys/compat/svr4/svr4_util.h
index 66902dd..54ed430 100644
--- a/sys/compat/svr4/svr4_util.h
+++ b/sys/compat/svr4/svr4_util.h
@@ -42,7 +42,10 @@
#include <sys/uio.h>
#ifdef DEBUG_SVR4
-#define DPRINTF(a) uprintf a;
+#define DPRINTF(a) do { \
+ mtx_lock(&Giant); \
+ uprintf a; \
+} while (0)
#else
#define DPRINTF(a)
#endif
OpenPOWER on IntegriCloud