Back out alpha/alpha/trap.c:1.124, osf1_ioctl.c:1.14, osf1_misc.c:1.57,

osf1_signal.c:1.41, amd64/amd64/trap.c:1.291, linux_socket.c:1.60,
svr4_fcntl.c:1.36, svr4_ioctl.c:1.23, svr4_ipc.c:1.18, svr4_misc.c:1.81,
svr4_signal.c:1.34, svr4_stat.c:1.21, svr4_stream.c:1.55,
svr4_termios.c:1.13, svr4_ttold.c:1.15, svr4_util.h:1.10,
ext2_alloc.c:1.43, i386/i386/trap.c:1.279, vm86.c:1.58,
unaligned.c:1.12, imgact_elf.c:1.164, ffs_alloc.c:1.133:

Now that Giant is acquired in uprintf() and tprintf(), the caller no
longer leads to acquire Giant unless it also holds another mutex that
would generate a lock order reversal when calling into these functions.
Specifically not backed out is the acquisition of Giant in nfs_socket.c
and rpcclnt.c, where local mutexes are held and would otherwise violate
the lock order with Giant.

This aligns this code more with the eventual locking of ttys.

Suggested by:	bde
This commit is contained in:
Robert Watson 2005-09-28 07:03:03 +00:00
parent 8c81e13758
commit 5f419982c2
22 changed files with 12 additions and 139 deletions

View File

@ -1046,14 +1046,12 @@ unaligned_fixup(va, opcode, reg, td)
* If we're supposed to be noisy, squawk now.
*/
if (doprint) {
mtx_lock(&Giant);
uprintf(
"pid %d (%s): unaligned access: va=0x%lx pc=0x%lx ra=0x%lx op=",
p->p_pid, p->p_comm, va, td->td_frame->tf_regs[FRAME_PC],
td->td_frame->tf_regs[FRAME_RA]);
uprintf(type,opcode);
uprintf("\n");
mtx_unlock(&Giant);
}
/*

View File

@ -33,8 +33,6 @@
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/systm.h>
#include <sys/fcntl.h>
#include <sys/filio.h>
@ -112,11 +110,9 @@ osf1_ioctl(td, uap)
break;
}
#ifdef IOCTL_DEBUG
mtx_lock(&Giant);
uprintf(
"OSF/1 IOCTL: group = %c, cmd = %d, len = %d, dir = %s\n",
group, cmd, len, dirstr);
mtx_unlock(&Giant);
#endif
a.fd = uap->fd;

View File

@ -209,10 +209,8 @@ osf1_getsysinfo(td, uap)
rpb_size = (unsigned long)&hwrpb->rpb_tbhint -
(unsigned long)hwrpb;
if(uap->nbytes < rpb_size){
mtx_lock(&Giant);
uprintf("nbytes = %ld, sizeof(struct rpb) = %ld\n",
uap->nbytes, rpb_size);
mtx_unlock(&Giant);
error = EINVAL;
}
else {
@ -256,9 +254,7 @@ osf1_setsysinfo(td, uap)
break;
}
default:
mtx_lock(&Giant);
uprintf("osf1_setsysinfo called with op=%ld\n", uap->op);
mtx_unlock(&Giant);
/*error = EINVAL;*/
}
return (error);

View File

@ -40,8 +40,6 @@ __FBSDID("$FreeBSD$");
#endif
#include <sys/param.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/systm.h>
#include <sys/sysproto.h>
#include <sys/signalvar.h>
@ -147,12 +145,9 @@ osf1_to_bsd_sigaction(osa, bsa)
{
bsa->sa_handler = osa->osa_handler;
if (osf1_sigdbg) {
mtx_lock(&Giant);
if (osf1_sigdbg)
uprintf("%s(%d): handler @0x%lx \n", __FILE__, __LINE__,
(unsigned long)osa->osa_handler);
mtx_unlock(&Giant);
}
osf1_to_bsd_sigset(&osa->osa_mask, &bsa->sa_mask);
bsa->sa_flags = 0;
if ((osa->osa_flags & OSF1_SA_ONSTACK) != 0)
@ -230,12 +225,9 @@ osf1_sigaction(td, uap)
struct sigaction *nbsap;
int error;
if (osf1_sigdbg && uap->sigtramp) {
mtx_lock(&Giant);
if (osf1_sigdbg && uap->sigtramp)
uprintf("osf1_sigaction: trampoline handler at %p\n",
uap->sigtramp);
mtx_unlock(&Giant);
}
td->td_md.osf_sigtramp = uap->sigtramp;
if (uap->nsa != NULL) {
if ((error = copyin(uap->nsa, &osa, sizeof(osa))) != 0)
@ -323,10 +315,8 @@ osf1_signal(td, uap)
#endif
error = kern_sigaction(td, signum, &nbsa, &obsa, 0);
if (error != 0) {
mtx_lock(&Giant);
DPRINTF("signal: sigaction failed: %d\n",
error);
mtx_unlock(&Giant);
td->td_retval[0] = -1;
return (error);
}
@ -362,11 +352,8 @@ osf1_signal(td, uap)
SIGEMPTYSET(sa.sa_mask);
sa.sa_flags = 0;
error = kern_sigaction(td, signum, &sa, NULL, 0);
if (error != 0) {
mtx_lock(&Giant);
if (error != 0)
DPRINTF(("sigignore: sigaction failed\n"));
mtx_unlock(&Giant);
}
return (error);
}
@ -557,11 +544,8 @@ osf1_sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code)
/*
* Set up the registers to return to sigcode.
*/
if (osf1_sigdbg) {
mtx_lock(&Giant);
if (osf1_sigdbg)
uprintf("attempting to call osf1 sigtramp\n");
mtx_unlock(&Giant);
}
frame->tf_regs[FRAME_PC] = (u_int64_t)td->td_md.osf_sigtramp;
frame->tf_regs[FRAME_A0] = sig;
frame->tf_regs[FRAME_A1] = code;
@ -643,9 +627,7 @@ osf1_osigstack(td, uap)
} */ *uap;
{
/* mtx_lock(&Giant);
uprintf("osf1_osigstack: oss = %p, nss = %p",uap->oss, uap->nss);
uprintf(" stack ptr = %p\n",p->p_sigacts->ps_sigstk.ss_sp);
mtx_unlock(&Giant); */
/* uprintf("osf1_osigstack: oss = %p, nss = %p",uap->oss, uap->nss);
uprintf(" stack ptr = %p\n",p->p_sigacts->ps_sigstk.ss_sp);*/
return(osigstack(td, (struct osigstack_args *)uap));
}

View File

@ -486,13 +486,11 @@ trap(frame)
#ifdef DEBUG
if (type <= MAX_TRAP_MSG) {
mtx_lock(&Giant);
uprintf("fatal process exception: %s",
trap_msg[type]);
if ((type == T_PAGEFLT) || (type == T_PROTFLT))
uprintf(", fault VA = 0x%lx", frame.tf_addr);
uprintf("\n");
mtx_unlock(&Giant);
}
#endif

View File

@ -1187,9 +1187,7 @@ linux_socketcall(struct thread *td, struct linux_socketcall_args *args)
return (linux_recvmsg(td, arg));
}
mtx_lock(&Giant);
uprintf("LINUX: 'socket' typ=%d not implemented\n", args->what);
mtx_unlock(&Giant);
return (ENOSYS);
}
#endif /*!__alpha__*/

View File

@ -377,10 +377,8 @@ svr4_sys_open(td, uap)
free(newpath, M_TEMP);
if (error) {
/* mtx_lock(&Giant);
uprintf("svr4_open(%s, 0x%0x, 0%o): %d\n", uap->path,
uap->flags, uap->mode, error);
mtx_unlock(&Giant);*/
/* uprintf("svr4_open(%s, 0x%0x, 0%o): %d\n", uap->path,
uap->flags, uap->mode, error);*/
return error;
}

View File

@ -30,8 +30,6 @@
__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>

View File

@ -77,9 +77,7 @@ __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>

View File

@ -485,9 +485,7 @@ svr4_sys_getdents(td, uap)
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;
}

View File

@ -238,11 +238,8 @@ 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) {
mtx_lock(&Giant);
if ((sss->ss_flags & ~SVR4_SS_ALLBITS) != 0)
/*XXX*/ uprintf("svr4_to_bsd_sigaltstack: extra bits ignored\n");
mtx_unlock(&Giant);
}
}
void

View File

@ -30,8 +30,6 @@
__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>

View File

@ -378,8 +378,6 @@ bufprint(buf, len)
{
size_t i;
GIANT_REQUIRED;
uprintf("\n\t");
for (i = 0; i < len; i++) {
uprintf("%x ", buf[i]);
@ -397,8 +395,6 @@ show_ioc(str, ioc)
int len;
int error;
GIANT_REQUIRED;
len = ioc->len;
if (len > 1024)
len = 1024;
@ -434,8 +430,6 @@ show_strbuf(str)
int maxlen = str->maxlen;
int len = str->len;
GIANT_REQUIRED;
if (maxlen > 8192)
maxlen = 8192;
@ -479,8 +473,6 @@ 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)
@ -1415,12 +1407,8 @@ i_str(fp, td, retval, fd, cmd, dat)
return error;
#ifdef DEBUG_SVR4
mtx_lock(&Giant);
if ((error = show_ioc(">", &ioc)) != 0) {
mtx_unlock(&Giant);
if ((error = show_ioc(">", &ioc)) != 0)
return error;
}
mtx_unlock(&Giant);
#endif /* DEBUG_SVR4 */
switch (ioc.cmd & 0xff00) {
@ -1441,12 +1429,8 @@ i_str(fp, td, retval, fd, cmd, dat)
}
#ifdef DEBUG_SVR4
mtx_lock(&Giant);
if ((error = show_ioc("<", &ioc)) != 0) {
mtx_lock(&Giant);
if ((error = show_ioc("<", &ioc)) != 0)
return error;
}
mtx_unlock(&Giant);
#endif /* DEBUG_SVR4 */
return copyout(&ioc, dat, sizeof(ioc));
}
@ -1566,9 +1550,7 @@ 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;
@ -1761,10 +1743,8 @@ 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);
@ -1960,10 +1940,8 @@ 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) {
@ -2271,10 +2249,8 @@ 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;
}

View File

@ -30,8 +30,6 @@
__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>
@ -158,9 +156,6 @@ 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: ");
@ -513,9 +508,7 @@ 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 */
@ -583,9 +576,7 @@ 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 */

View File

@ -32,8 +32,6 @@ __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>
@ -71,8 +69,6 @@ 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);
@ -83,9 +79,6 @@ 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);
@ -96,9 +89,6 @@ 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);
@ -241,9 +231,7 @@ 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
}
@ -260,9 +248,7 @@ 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));
}
@ -278,9 +264,7 @@ 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,
@ -299,9 +283,7 @@ 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));
}
@ -316,9 +298,7 @@ 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);
@ -336,9 +316,7 @@ 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));
}
@ -353,9 +331,7 @@ 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);

View File

@ -42,10 +42,7 @@
#include <sys/uio.h>
#ifdef DEBUG_SVR4
#define DPRINTF(a) do { \
mtx_lock(&Giant); \
uprintf a; \
} while (0)
#define DPRINTF(a) uprintf a;
#else
#define DPRINTF(a)
#endif

View File

@ -165,7 +165,6 @@ ext2_alloc(ip, lbn, bpref, size, cred, bnp)
}
nospace:
ext2_fserr(fs, cred->cr_uid, "file system full");
GIANT_REQUIRED; /* uprintf */
uprintf("\n%s: write failed, file system is full\n", fs->fs_fsmnt);
return (ENOSPC);
}
@ -412,7 +411,6 @@ printf("ext2_valloc: allocated inode %d\n", ino);
return (0);
noinodes:
ext2_fserr(fs, cred->cr_uid, "out of inodes");
GIANT_REQUIRED; /* uprintf */
uprintf("\n%s: create/symlink failed, no inodes free\n", fs->fs_fsmnt);
return (ENOSPC);
}

View File

@ -648,13 +648,11 @@ trap(frame)
#ifdef DEBUG
if (type <= MAX_TRAP_MSG) {
mtx_lock(&Giant);
uprintf("fatal process exception: %s",
trap_msg[type]);
if ((type == T_PAGEFLT) || (type == T_PROTFLT))
uprintf(", fault VA = 0x%lx", (u_long)eva);
uprintf("\n");
mtx_unlock(&Giant);
}
#endif

View File

@ -193,9 +193,7 @@ vm86_emulate(vmf)
vmf->vmf_eflags |= PSL_VIF;
vmf->vmf_ip += inc_ip;
if ((vmf->vmf_eflags & PSL_VIP) == 0) {
mtx_lock(&Giant);
uprintf("fatal sti\n");
mtx_unlock(&Giant);
return (SIGKILL);
}
break;

View File

@ -30,8 +30,6 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/sysctl.h>
#include <vm/vm.h>
@ -265,11 +263,9 @@ unaligned_fixup(struct trapframe *tf, struct thread *td)
((tf->tf_special.psr & IA64_PSR_RI) == IA64_PSR_RI_1) ? 1 : 2;
if (ia64_unaligned_print) {
mtx_lock(&Giant);
uprintf("pid %d (%s): unaligned access: va=0x%lx, pc=0x%lx\n",
td->td_proc->p_pid, td->td_proc->p_comm,
tf->tf_special.ifa, tf->tf_special.iip + slot);
mtx_unlock(&Giant);
}
/*

View File

@ -380,9 +380,7 @@ __elfN(load_section)(struct proc *p, struct vmspace *vmspace,
*/
if ((off_t)filsz + offset > object->un_pager.vnp.vnp_size ||
filsz > memsz) {
mtx_lock(&Giant);
uprintf("elf_load_section: truncated ELF file\n");
mtx_unlock(&Giant);
return (ENOEXEC);
}
@ -700,10 +698,8 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp)
brand_info = __elfN(get_brandinfo)(hdr, interp);
if (brand_info == NULL) {
mtx_lock(&Giant);
uprintf("ELF binary type \"%u\" not known.\n",
hdr->e_ident[EI_OSABI]);
mtx_unlock(&Giant);
error = ENOEXEC;
goto fail;
}
@ -844,9 +840,7 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp)
error = __elfN(load_file)(imgp->proc, interp, &addr,
&imgp->entry_addr, sv->sv_pagesize);
if (error != 0) {
mtx_lock(&Giant);
uprintf("ELF interpreter %s not found\n", interp);
mtx_unlock(&Giant);
goto fail;
}
}

View File

@ -201,9 +201,7 @@ ffs_alloc(ip, lbn, bpref, size, cred, bnp)
}
UFS_UNLOCK(ump);
ffs_fserr(fs, ip->i_number, "filesystem full");
mtx_lock(&Giant);
uprintf("\n%s: write failed, filesystem is full\n", fs->fs_fsmnt);
mtx_unlock(&Giant);
return (ENOSPC);
}
@ -401,9 +399,7 @@ ffs_realloccg(ip, lbprev, bprev, bpref, osize, nsize, cred, bpp)
if (bp)
brelse(bp);
ffs_fserr(fs, ip->i_number, "filesystem full");
mtx_lock(&Giant);
uprintf("\n%s: write failed, filesystem is full\n", fs->fs_fsmnt);
mtx_unlock(&Giant);
return (ENOSPC);
}
@ -958,9 +954,7 @@ ffs_valloc(pvp, mode, cred, vpp)
noinodes:
UFS_UNLOCK(ump);
ffs_fserr(fs, pip->i_number, "out of inodes");
mtx_lock(&Giant);
uprintf("\n%s: create/symlink failed, no inodes free\n", fs->fs_fsmnt);
mtx_unlock(&Giant);
return (ENOSPC);
}