From owner-svn-src-all@FreeBSD.ORG Fri Jan 22 17:02:07 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 849A310656AC; Fri, 22 Jan 2010 17:02:07 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 7088F8FC08; Fri, 22 Jan 2010 17:02:07 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o0MH27OO030590; Fri, 22 Jan 2010 17:02:07 GMT (envelope-from jhb@svn.freebsd.org) Received: (from jhb@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o0MH27aT030573; Fri, 22 Jan 2010 17:02:07 GMT (envelope-from jhb@svn.freebsd.org) Message-Id: <201001221702.o0MH27aT030573@svn.freebsd.org> From: John Baldwin Date: Fri, 22 Jan 2010 17:02:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r202814 - in stable/7/sys: cam/scsi i386/acpica kern net security/audit sys X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Jan 2010 17:02:07 -0000 Author: jhb Date: Fri Jan 22 17:02:07 2010 New Revision: 202814 URL: http://svn.freebsd.org/changeset/base/202814 Log: MFC 193951: Adapt vfs kqfilter to the shared vnode lock used by zfs write vop. Use vnode interlock to protect the knote fields. The locking assumes that shared vnode lock is held, thus we get exclusive access to knote either by exclusive vnode lock protection, or by shared vnode lock + vnode interlock. Unlike the change in HEAD, this does not remove kl_locked() and replace it with kl_assert_locked() and kl_assert_unlocked(). Instead, the kl_locked can now be set to NULL in which case no assertion checks are performed on the lock. The vfs kqfilter code uses this mode to disable assertion checks. This preserves the existing ABI for knlist_init(). Add convenience function knlist_init_mtx to reduce number of arguments for typical knlist initialization. Reviewed by: kib Modified: stable/7/sys/cam/scsi/scsi_target.c stable/7/sys/i386/acpica/acpi_machdep.c stable/7/sys/kern/init_main.c stable/7/sys/kern/kern_event.c stable/7/sys/kern/kern_fork.c stable/7/sys/kern/sys_pipe.c stable/7/sys/kern/tty.c stable/7/sys/kern/uipc_mqueue.c stable/7/sys/kern/uipc_socket.c stable/7/sys/kern/vfs_aio.c stable/7/sys/kern/vfs_subr.c stable/7/sys/net/bpf.c stable/7/sys/net/if_tap.c stable/7/sys/net/if_tun.c stable/7/sys/security/audit/audit_pipe.c stable/7/sys/sys/event.h Directory Properties: stable/7/sys/ (props changed) stable/7/sys/cddl/contrib/opensolaris/ (props changed) stable/7/sys/contrib/dev/acpica/ (props changed) stable/7/sys/contrib/pf/ (props changed) Modified: stable/7/sys/cam/scsi/scsi_target.c ============================================================================== --- stable/7/sys/cam/scsi/scsi_target.c Fri Jan 22 16:23:00 2010 (r202813) +++ stable/7/sys/cam/scsi/scsi_target.c Fri Jan 22 17:02:07 2010 (r202814) @@ -194,7 +194,7 @@ targopen(struct cdev *dev, int flags, in TAILQ_INIT(&softc->work_queue); TAILQ_INIT(&softc->abort_queue); TAILQ_INIT(&softc->user_ccb_queue); - knlist_init(&softc->read_select.si_note, NULL, NULL, NULL, NULL); + knlist_init_mtx(&softc->read_select.si_note, NULL); return (0); } Modified: stable/7/sys/i386/acpica/acpi_machdep.c ============================================================================== --- stable/7/sys/i386/acpica/acpi_machdep.c Fri Jan 22 16:23:00 2010 (r202813) +++ stable/7/sys/i386/acpica/acpi_machdep.c Fri Jan 22 17:02:07 2010 (r202814) @@ -258,7 +258,7 @@ apm_create_clone(struct cdev *dev, struc clone->acpi_sc = acpi_sc; clone->notify_status = APM_EV_NONE; bzero(&clone->sel_read, sizeof(clone->sel_read)); - knlist_init(&clone->sel_read.si_note, &acpi_mutex, NULL, NULL, NULL); + knlist_init_mtx(&clone->sel_read.si_note, &acpi_mutex); /* * The acpi device is always managed by devd(8) and is considered Modified: stable/7/sys/kern/init_main.c ============================================================================== --- stable/7/sys/kern/init_main.c Fri Jan 22 16:23:00 2010 (r202813) +++ stable/7/sys/kern/init_main.c Fri Jan 22 17:02:07 2010 (r202814) @@ -435,7 +435,7 @@ proc0_init(void *dummy __unused) p->p_sysent = &null_sysvec; p->p_flag = P_SYSTEM | P_INMEM; p->p_state = PRS_NORMAL; - knlist_init(&p->p_klist, &p->p_mtx, NULL, NULL, NULL); + knlist_init_mtx(&p->p_klist, &p->p_mtx); STAILQ_INIT(&p->p_ktr); p->p_nice = NZERO; td->td_tid = PID_MAX + 1; Modified: stable/7/sys/kern/kern_event.c ============================================================================== --- stable/7/sys/kern/kern_event.c Fri Jan 22 16:23:00 2010 (r202813) +++ stable/7/sys/kern/kern_event.c Fri Jan 22 17:02:07 2010 (r202814) @@ -206,11 +206,13 @@ SYSCTL_INT(_kern, OID_AUTO, kq_calloutma } while (0) #ifdef INVARIANTS #define KNL_ASSERT_LOCKED(knl) do { \ - if (!knl->kl_locked((knl)->kl_lockarg)) \ + if (knl->kl_locked != NULL && \ + !knl->kl_locked((knl)->kl_lockarg)) \ panic("knlist not locked, but should be"); \ } while (0) #define KNL_ASSERT_UNLOCKED(knl) do { \ - if (knl->kl_locked((knl)->kl_lockarg)) \ + if (knl->kl_locked != NULL && \ + knl->kl_locked((knl)->kl_lockarg)) \ panic("knlist locked, but should not be"); \ } while (0) #else /* !INVARIANTS */ @@ -576,7 +578,7 @@ kqueue(struct thread *td, struct kqueue_ mtx_init(&kq->kq_lock, "kqueue", NULL, MTX_DEF|MTX_DUPOK); TAILQ_INIT(&kq->kq_head); kq->kq_fdp = fdp; - knlist_init(&kq->kq_sel.si_note, &kq->kq_lock, NULL, NULL, NULL); + knlist_init_mtx(&kq->kq_sel.si_note, &kq->kq_lock); TASK_INIT(&kq->kq_task, 0, kqueue_task, kq); FILEDESC_XLOCK(fdp); @@ -1774,7 +1776,7 @@ knlist_init(struct knlist *knl, void *lo knl->kl_unlock = knlist_mtx_unlock; else knl->kl_unlock = kl_unlock; - if (kl_locked == NULL) + if (kl_locked == NULL && kl_lock == NULL && kl_unlock == NULL) knl->kl_locked = knlist_mtx_locked; else knl->kl_locked = kl_locked; @@ -1783,6 +1785,13 @@ knlist_init(struct knlist *knl, void *lo } void +knlist_init_mtx(struct knlist *knl, struct mtx *lock) +{ + + knlist_init(knl, lock, NULL, NULL, NULL); +} + +void knlist_destroy(struct knlist *knl) { Modified: stable/7/sys/kern/kern_fork.c ============================================================================== --- stable/7/sys/kern/kern_fork.c Fri Jan 22 16:23:00 2010 (r202813) +++ stable/7/sys/kern/kern_fork.c Fri Jan 22 17:02:07 2010 (r202814) @@ -294,7 +294,7 @@ norfproc_fail: #ifdef MAC mac_init_proc(newproc); #endif - knlist_init(&newproc->p_klist, &newproc->p_mtx, NULL, NULL, NULL); + knlist_init_mtx(&newproc->p_klist, &newproc->p_mtx); STAILQ_INIT(&newproc->p_ktr); /* We have to lock the process tree while we look for a pid. */ Modified: stable/7/sys/kern/sys_pipe.c ============================================================================== --- stable/7/sys/kern/sys_pipe.c Fri Jan 22 16:23:00 2010 (r202813) +++ stable/7/sys/kern/sys_pipe.c Fri Jan 22 17:02:07 2010 (r202814) @@ -332,10 +332,8 @@ pipe(td, uap) rpipe = &pp->pp_rpipe; wpipe = &pp->pp_wpipe; - knlist_init(&rpipe->pipe_sel.si_note, PIPE_MTX(rpipe), NULL, NULL, - NULL); - knlist_init(&wpipe->pipe_sel.si_note, PIPE_MTX(wpipe), NULL, NULL, - NULL); + knlist_init_mtx(&rpipe->pipe_sel.si_note, PIPE_MTX(rpipe)); + knlist_init_mtx(&wpipe->pipe_sel.si_note, PIPE_MTX(wpipe)); /* Only the forward direction pipe is backed by default */ if ((error = pipe_create(rpipe, 1)) != 0 || Modified: stable/7/sys/kern/tty.c ============================================================================== --- stable/7/sys/kern/tty.c Fri Jan 22 16:23:00 2010 (r202813) +++ stable/7/sys/kern/tty.c Fri Jan 22 17:02:07 2010 (r202814) @@ -2904,8 +2904,8 @@ ttyalloc() mtx_lock(&tty_list_mutex); TAILQ_INSERT_TAIL(&tty_list, tp, t_list); mtx_unlock(&tty_list_mutex); - knlist_init(&tp->t_rsel.si_note, &tp->t_mtx, NULL, NULL, NULL); - knlist_init(&tp->t_wsel.si_note, &tp->t_mtx, NULL, NULL, NULL); + knlist_init_mtx(&tp->t_rsel.si_note, &tp->t_mtx); + knlist_init_mtx(&tp->t_wsel.si_note, &tp->t_mtx); return (tp); } Modified: stable/7/sys/kern/uipc_mqueue.c ============================================================================== --- stable/7/sys/kern/uipc_mqueue.c Fri Jan 22 16:23:00 2010 (r202813) +++ stable/7/sys/kern/uipc_mqueue.c Fri Jan 22 17:02:07 2010 (r202814) @@ -1502,8 +1502,8 @@ mqueue_alloc(const struct mq_attr *attr) mq->mq_msgsize = default_msgsize; } mtx_init(&mq->mq_mutex, "mqueue", NULL, MTX_DEF); - knlist_init(&mq->mq_rsel.si_note, &mq->mq_mutex, NULL, NULL, NULL); - knlist_init(&mq->mq_wsel.si_note, &mq->mq_mutex, NULL, NULL, NULL); + knlist_init_mtx(&mq->mq_rsel.si_note, &mq->mq_mutex); + knlist_init_mtx(&mq->mq_wsel.si_note, &mq->mq_mutex); atomic_add_int(&curmq, 1); return (mq); } Modified: stable/7/sys/kern/uipc_socket.c ============================================================================== --- stable/7/sys/kern/uipc_socket.c Fri Jan 22 16:23:00 2010 (r202813) +++ stable/7/sys/kern/uipc_socket.c Fri Jan 22 17:02:07 2010 (r202814) @@ -370,10 +370,8 @@ socreate(int dom, struct socket **aso, i #ifdef MAC mac_create_socket(cred, so); #endif - knlist_init(&so->so_rcv.sb_sel.si_note, SOCKBUF_MTX(&so->so_rcv), - NULL, NULL, NULL); - knlist_init(&so->so_snd.sb_sel.si_note, SOCKBUF_MTX(&so->so_snd), - NULL, NULL, NULL); + knlist_init_mtx(&so->so_rcv.sb_sel.si_note, SOCKBUF_MTX(&so->so_rcv)); + knlist_init_mtx(&so->so_snd.sb_sel.si_note, SOCKBUF_MTX(&so->so_snd)); so->so_count = 1; /* * Auto-sizing of socket buffers is managed by the protocols and @@ -439,10 +437,8 @@ sonewconn(struct socket *head, int conns mac_create_socket_from_socket(head, so); SOCK_UNLOCK(head); #endif - knlist_init(&so->so_rcv.sb_sel.si_note, SOCKBUF_MTX(&so->so_rcv), - NULL, NULL, NULL); - knlist_init(&so->so_snd.sb_sel.si_note, SOCKBUF_MTX(&so->so_snd), - NULL, NULL, NULL); + knlist_init_mtx(&so->so_rcv.sb_sel.si_note, SOCKBUF_MTX(&so->so_rcv)); + knlist_init_mtx(&so->so_snd.sb_sel.si_note, SOCKBUF_MTX(&so->so_snd)); if (soreserve(so, head->so_snd.sb_hiwat, head->so_rcv.sb_hiwat) || (*so->so_proto->pr_usrreqs->pru_attach)(so, 0, NULL)) { sodealloc(so); Modified: stable/7/sys/kern/vfs_aio.c ============================================================================== --- stable/7/sys/kern/vfs_aio.c Fri Jan 22 16:23:00 2010 (r202813) +++ stable/7/sys/kern/vfs_aio.c Fri Jan 22 17:02:07 2010 (r202814) @@ -1486,7 +1486,7 @@ aio_aqueue(struct thread *td, struct aio aiocbe = uma_zalloc(aiocb_zone, M_WAITOK | M_ZERO); aiocbe->inputcharge = 0; aiocbe->outputcharge = 0; - knlist_init(&aiocbe->klist, AIO_MTX(ki), NULL, NULL, NULL); + knlist_init_mtx(&aiocbe->klist, AIO_MTX(ki)); error = ops->copyin(job, &aiocbe->uaiocb); if (error) { @@ -2108,7 +2108,7 @@ kern_lio_listio(struct thread *td, int m lj->lioj_flags = 0; lj->lioj_count = 0; lj->lioj_finished_count = 0; - knlist_init(&lj->klist, AIO_MTX(ki), NULL, NULL, NULL); + knlist_init_mtx(&lj->klist, AIO_MTX(ki)); ksiginfo_init(&lj->lioj_ksi); /* Modified: stable/7/sys/kern/vfs_subr.c ============================================================================== --- stable/7/sys/kern/vfs_subr.c Fri Jan 22 16:23:00 2010 (r202813) +++ stable/7/sys/kern/vfs_subr.c Fri Jan 22 17:02:07 2010 (r202814) @@ -107,7 +107,6 @@ static void vnlru_free(int); static void vgonel(struct vnode *); static void vfs_knllock(void *arg); static void vfs_knlunlock(void *arg); -static int vfs_knllocked(void *arg); static void destroy_vpollinfo(struct vpollinfo *vi); /* @@ -3227,7 +3226,7 @@ v_addpollinfo(struct vnode *vp) vi = uma_zalloc(vnodepoll_zone, M_WAITOK); mtx_init(&vi->vpi_lock, "vnode pollinfo", NULL, MTX_DEF); knlist_init(&vi->vpi_selinfo.si_note, vp, vfs_knllock, - vfs_knlunlock, vfs_knllocked); + vfs_knlunlock, NULL); VI_LOCK(vp); if (vp->v_pollinfo != NULL) { VI_UNLOCK(vp); @@ -3945,7 +3944,7 @@ static struct knlist fs_knlist; static void vfs_event_init(void *arg) { - knlist_init(&fs_knlist, NULL, NULL, NULL, NULL); + knlist_init_mtx(&fs_knlist, NULL); } /* XXX - correct order? */ SYSINIT(vfs_knlist, SI_SUB_VFS, SI_ORDER_ANY, vfs_event_init, NULL); @@ -4058,14 +4057,6 @@ vfs_knlunlock(void *arg) VOP_UNLOCK(vp, 0, curthread); } -static int -vfs_knllocked(void *arg) -{ - struct vnode *vp = arg; - - return (VOP_ISLOCKED(vp, curthread) == LK_EXCLUSIVE); -} - int vfs_kqfilter(struct vop_kqfilter_args *ap) { @@ -4116,27 +4107,37 @@ filt_vfsread(struct knote *kn, long hint { struct vnode *vp = (struct vnode *)kn->kn_hook; struct vattr va; + int res; /* * filesystem is gone, so set the EOF flag and schedule * the knote for deletion. */ if (hint == NOTE_REVOKE) { + VI_LOCK(vp); kn->kn_flags |= (EV_EOF | EV_ONESHOT); + VI_UNLOCK(vp); return (1); } if (VOP_GETATTR(vp, &va, curthread->td_ucred, curthread)) return (0); + VI_LOCK(vp); kn->kn_data = va.va_size - kn->kn_fp->f_offset; - return (kn->kn_data != 0); + res = (kn->kn_data != 0); + VI_UNLOCK(vp); + return (res); } /*ARGSUSED*/ static int filt_vfswrite(struct knote *kn, long hint) { + struct vnode *vp = (struct vnode *)kn->kn_hook; + + VI_LOCK(vp); + /* * filesystem is gone, so set the EOF flag and schedule * the knote for deletion. @@ -4145,19 +4146,27 @@ filt_vfswrite(struct knote *kn, long hin kn->kn_flags |= (EV_EOF | EV_ONESHOT); kn->kn_data = 0; + VI_UNLOCK(vp); return (1); } static int filt_vfsvnode(struct knote *kn, long hint) { + struct vnode *vp = (struct vnode *)kn->kn_hook; + int res; + + VI_LOCK(vp); if (kn->kn_sfflags & hint) kn->kn_fflags |= hint; if (hint == NOTE_REVOKE) { kn->kn_flags |= EV_EOF; + VI_UNLOCK(vp); return (1); } - return (kn->kn_fflags != 0); + res = (kn->kn_fflags != 0); + VI_UNLOCK(vp); + return (res); } int Modified: stable/7/sys/net/bpf.c ============================================================================== --- stable/7/sys/net/bpf.c Fri Jan 22 16:23:00 2010 (r202813) +++ stable/7/sys/net/bpf.c Fri Jan 22 17:02:07 2010 (r202814) @@ -425,7 +425,7 @@ bpfopen(struct cdev *dev, int flags, int #endif mtx_init(&d->bd_mtx, devtoname(dev), "bpf cdev lock", MTX_DEF); callout_init(&d->bd_callout, CALLOUT_MPSAFE); - knlist_init(&d->bd_sel.si_note, &d->bd_mtx, NULL, NULL, NULL); + knlist_init_mtx(&d->bd_sel.si_note, &d->bd_mtx); return (0); } Modified: stable/7/sys/net/if_tap.c ============================================================================== --- stable/7/sys/net/if_tap.c Fri Jan 22 16:23:00 2010 (r202813) +++ stable/7/sys/net/if_tap.c Fri Jan 22 17:02:07 2010 (r202814) @@ -462,7 +462,7 @@ tapcreate(struct cdev *dev) tp->tap_flags |= TAP_INITED; mtx_unlock(&tp->tap_mtx); - knlist_init(&tp->tap_rsel.si_note, NULL, NULL, NULL, NULL); + knlist_init_mtx(&tp->tap_rsel.si_note, NULL); TAPDEBUG("interface %s is created. minor = %#x\n", ifp->if_xname, minor(dev)); Modified: stable/7/sys/net/if_tun.c ============================================================================== --- stable/7/sys/net/if_tun.c Fri Jan 22 16:23:00 2010 (r202813) +++ stable/7/sys/net/if_tun.c Fri Jan 22 17:02:07 2010 (r202814) @@ -380,7 +380,7 @@ tuncreate(const char *name, struct cdev IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen); ifp->if_snd.ifq_drv_maxlen = 0; IFQ_SET_READY(&ifp->if_snd); - knlist_init(&sc->tun_rsel.si_note, NULL, NULL, NULL, NULL); + knlist_init_mtx(&sc->tun_rsel.si_note, NULL); if_attach(ifp); bpfattach(ifp, DLT_NULL, sizeof(u_int32_t)); Modified: stable/7/sys/security/audit/audit_pipe.c ============================================================================== --- stable/7/sys/security/audit/audit_pipe.c Fri Jan 22 16:23:00 2010 (r202813) +++ stable/7/sys/security/audit/audit_pipe.c Fri Jan 22 17:02:07 2010 (r202814) @@ -579,8 +579,7 @@ audit_pipe_alloc(void) return (NULL); ap->ap_qlimit = AUDIT_PIPE_QLIMIT_DEFAULT; TAILQ_INIT(&ap->ap_queue); - knlist_init(&ap->ap_selinfo.si_note, AUDIT_PIPE_MTX(ap), NULL, NULL, - NULL); + knlist_init_mtx(&ap->ap_selinfo.si_note, AUDIT_PIPE_MTX(ap)); AUDIT_PIPE_LOCK_INIT(ap); AUDIT_PIPE_SX_LOCK_INIT(ap); cv_init(&ap->ap_cv, "audit_pipe"); Modified: stable/7/sys/sys/event.h ============================================================================== --- stable/7/sys/sys/event.h Fri Jan 22 16:23:00 2010 (r202813) +++ stable/7/sys/sys/event.h Fri Jan 22 17:02:07 2010 (r202814) @@ -209,6 +209,7 @@ struct kevent_copyops { struct thread; struct proc; struct knlist; +struct mtx; extern void knote(struct knlist *list, long hint, int lockflags); extern void knote_fork(struct knlist *list, int pid); @@ -219,6 +220,7 @@ extern int knlist_empty(struct knlist *k extern void knlist_init(struct knlist *knl, void *lock, void (*kl_lock)(void *), void (*kl_unlock)(void *), int (*kl_locked)(void *)); +extern void knlist_init_mtx(struct knlist *knl, struct mtx *lock); extern void knlist_destroy(struct knlist *knl); extern void knlist_cleardel(struct knlist *knl, struct thread *td, int islocked, int killkn);