From owner-svn-src-stable@FreeBSD.ORG Sun Sep 5 14:02:34 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B6F6F10656C4; Sun, 5 Sep 2010 14:02:34 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A5D758FC13; Sun, 5 Sep 2010 14:02:34 +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 o85E2YXt082355; Sun, 5 Sep 2010 14:02:34 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o85E2Yem082353; Sun, 5 Sep 2010 14:02:34 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201009051402.o85E2Yem082353@svn.freebsd.org> From: Konstantin Belousov Date: Sun, 5 Sep 2010 14:02:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212226 - stable/8/sys/dev/null X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Sep 2010 14:02:34 -0000 Author: kib Date: Sun Sep 5 14:02:34 2010 New Revision: 212226 URL: http://svn.freebsd.org/changeset/base/212226 Log: MFC r196885 (by ed): Remove unneeded minor numbers from /dev/null and /dev/zero. Modified: stable/8/sys/dev/null/null.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/dev/null/null.c ============================================================================== --- stable/8/sys/dev/null/null.c Sun Sep 5 13:41:45 2010 (r212225) +++ stable/8/sys/dev/null/null.c Sun Sep 5 14:02:34 2010 (r212226) @@ -49,9 +49,6 @@ static d_write_t null_write; static d_ioctl_t null_ioctl; static d_read_t zero_read; -#define NULL_MINOR 2 -#define ZERO_MINOR 12 - static struct cdevsw null_cdevsw = { .d_version = D_VERSION, .d_read = (d_read_t *)nullop, @@ -115,10 +112,10 @@ null_modevent(module_t mod __unused, int if (bootverbose) printf("null: \n"); zbuf = (void *)malloc(PAGE_SIZE, M_TEMP, M_WAITOK | M_ZERO); - null_dev = make_dev(&null_cdevsw, NULL_MINOR, UID_ROOT, - GID_WHEEL, 0666, "null"); - zero_dev = make_dev(&zero_cdevsw, ZERO_MINOR, UID_ROOT, - GID_WHEEL, 0666, "zero"); + null_dev = make_dev(&null_cdevsw, 0, UID_ROOT, GID_WHEEL, + 0666, "null"); + zero_dev = make_dev(&zero_cdevsw, 0, UID_ROOT, GID_WHEEL, + 0666, "zero"); break; case MOD_UNLOAD: From owner-svn-src-stable@FreeBSD.ORG Sun Sep 5 14:16:35 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7ACB310656A6; Sun, 5 Sep 2010 14:16:35 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 69FBA8FC0C; Sun, 5 Sep 2010 14:16:35 +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 o85EGZWt082963; Sun, 5 Sep 2010 14:16:35 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o85EGZin082961; Sun, 5 Sep 2010 14:16:35 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201009051416.o85EGZin082961@svn.freebsd.org> From: Konstantin Belousov Date: Sun, 5 Sep 2010 14:16:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212227 - stable/8/sys/fs/devfs X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Sep 2010 14:16:35 -0000 Author: kib Date: Sun Sep 5 14:16:35 2010 New Revision: 212227 URL: http://svn.freebsd.org/changeset/base/212227 Log: MFC r210918: Initialize VV_ISTTY vnode flag on the devfs vnode creation instead of doing it on each open. Modified: stable/8/sys/fs/devfs/devfs_vnops.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/fs/devfs/devfs_vnops.c ============================================================================== --- stable/8/sys/fs/devfs/devfs_vnops.c Sun Sep 5 14:02:34 2010 (r212226) +++ stable/8/sys/fs/devfs/devfs_vnops.c Sun Sep 5 14:16:35 2010 (r212227) @@ -337,6 +337,7 @@ devfs_allocv(struct devfs_dirent *de, st struct vnode *vp; struct cdev *dev; struct devfs_mount *dmp; + struct cdevsw *dsw; dmp = VFSTODEVFS(mp); if (de->de_flags & DE_DOOMED) { @@ -393,6 +394,10 @@ devfs_allocv(struct devfs_dirent *de, st KASSERT(vp->v_usecount == 1, ("%s %d (%d)\n", __func__, __LINE__, vp->v_usecount)); dev->si_usecount += vp->v_usecount; + /* Special casing of ttys for deadfs. Probably redundant. */ + dsw = dev->si_devsw; + if (dsw != NULL && (dsw->d_flags & D_TTY) != 0) + vp->v_vflag |= VV_ISTTY; dev_unlock(); VI_UNLOCK(vp); vp->v_op = &devfs_specops; @@ -964,10 +969,6 @@ devfs_open(struct vop_open_args *ap) if (dsw == NULL) return (ENXIO); - /* XXX: Special casing of ttys for deadfs. Probably redundant. */ - if (dsw->d_flags & D_TTY) - vp->v_vflag |= VV_ISTTY; - VOP_UNLOCK(vp, 0); fpop = td->td_fpop; From owner-svn-src-stable@FreeBSD.ORG Sun Sep 5 14:20:34 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C705F1065697; Sun, 5 Sep 2010 14:20:34 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 7D28F8FC0C; Sun, 5 Sep 2010 14:20:34 +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 o85EKYQe083163; Sun, 5 Sep 2010 14:20:34 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o85EKY6U083159; Sun, 5 Sep 2010 14:20:34 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201009051420.o85EKY6U083159@svn.freebsd.org> From: Konstantin Belousov Date: Sun, 5 Sep 2010 14:20:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212228 - stable/8/sys/fs/devfs X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Sep 2010 14:20:34 -0000 Author: kib Date: Sun Sep 5 14:20:34 2010 New Revision: 212228 URL: http://svn.freebsd.org/changeset/base/212228 Log: MFC r210921: Enable shared locks for the devfs vnodes. Honor the locking mode requested by lookup(). Modified: stable/8/sys/fs/devfs/devfs.h stable/8/sys/fs/devfs/devfs_vfsops.c stable/8/sys/fs/devfs/devfs_vnops.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/fs/devfs/devfs.h ============================================================================== --- stable/8/sys/fs/devfs/devfs.h Sun Sep 5 14:16:35 2010 (r212227) +++ stable/8/sys/fs/devfs/devfs.h Sun Sep 5 14:20:34 2010 (r212228) @@ -172,7 +172,7 @@ extern unsigned devfs_rule_depth; void devfs_rules_apply(struct devfs_mount *dm, struct devfs_dirent *de); void devfs_rules_cleanup (struct devfs_mount *dm); int devfs_rules_ioctl(struct devfs_mount *dm, u_long cmd, caddr_t data, struct thread *td); -int devfs_allocv (struct devfs_dirent *de, struct mount *mp, +int devfs_allocv(struct devfs_dirent *de, struct mount *mp, int lockmode, struct vnode **vpp); void devfs_delete(struct devfs_mount *dm, struct devfs_dirent *de, int vp_locked); void devfs_dirent_free(struct devfs_dirent *de); Modified: stable/8/sys/fs/devfs/devfs_vfsops.c ============================================================================== --- stable/8/sys/fs/devfs/devfs_vfsops.c Sun Sep 5 14:16:35 2010 (r212227) +++ stable/8/sys/fs/devfs/devfs_vfsops.c Sun Sep 5 14:20:34 2010 (r212228) @@ -155,7 +155,7 @@ devfs_root(struct mount *mp, int flags, dmp = VFSTODEVFS(mp); sx_xlock(&dmp->dm_lock); - error = devfs_allocv(dmp->dm_rootdir, mp, &vp); + error = devfs_allocv(dmp->dm_rootdir, mp, LK_EXCLUSIVE, &vp); if (error) return (error); vp->v_vflag |= VV_ROOT; Modified: stable/8/sys/fs/devfs/devfs_vnops.c ============================================================================== --- stable/8/sys/fs/devfs/devfs_vnops.c Sun Sep 5 14:16:35 2010 (r212227) +++ stable/8/sys/fs/devfs/devfs_vnops.c Sun Sep 5 14:20:34 2010 (r212228) @@ -331,7 +331,8 @@ devfs_insmntque_dtr(struct vnode *vp, vo * it on return. */ int -devfs_allocv(struct devfs_dirent *de, struct mount *mp, struct vnode **vpp) +devfs_allocv(struct devfs_dirent *de, struct mount *mp, int lockmode, + struct vnode **vpp) { int error; struct vnode *vp; @@ -352,7 +353,7 @@ devfs_allocv(struct devfs_dirent *de, st VI_LOCK(vp); mtx_unlock(&devfs_de_interlock); sx_xunlock(&dmp->dm_lock); - error = vget(vp, LK_EXCLUSIVE | LK_INTERLOCK, curthread); + error = vget(vp, lockmode | LK_INTERLOCK, curthread); sx_xlock(&dmp->dm_lock); if (devfs_allocv_drop_refs(0, dmp, de)) { if (error == 0) @@ -408,6 +409,7 @@ devfs_allocv(struct devfs_dirent *de, st } else { vp->v_type = VBAD; } + VN_LOCK_ASHARE(vp); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY | LK_NOWITNESS); mtx_lock(&devfs_de_interlock); vp->v_data = de; @@ -747,7 +749,7 @@ devfs_lookupx(struct vop_lookup_args *ap struct devfs_dirent **dde; struct devfs_mount *dmp; struct cdev *cdev; - int error, flags, nameiop; + int error, flags, nameiop, dvplocked; char specname[SPECNAMELEN + 1], *pname; cnp = ap->a_cnp; @@ -788,10 +790,12 @@ devfs_lookupx(struct vop_lookup_args *ap de = devfs_parent_dirent(dd); if (de == NULL) return (ENOENT); + dvplocked = VOP_ISLOCKED(dvp); VOP_UNLOCK(dvp, 0); - error = devfs_allocv(de, dvp->v_mount, vpp); + error = devfs_allocv(de, dvp->v_mount, + cnp->cn_lkflags & LK_TYPE_MASK, vpp); *dm_unlock = 0; - vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY); + vn_lock(dvp, dvplocked | LK_RETRY); return (error); } @@ -878,7 +882,8 @@ devfs_lookupx(struct vop_lookup_args *ap return (0); } } - error = devfs_allocv(de, dvp->v_mount, vpp); + error = devfs_allocv(de, dvp->v_mount, cnp->cn_lkflags & LK_TYPE_MASK, + vpp); *dm_unlock = 0; return (error); } @@ -936,7 +941,7 @@ devfs_mknod(struct vop_mknod_args *ap) if (de == NULL) goto notfound; de->de_flags &= ~DE_WHITEOUT; - error = devfs_allocv(de, dvp->v_mount, vpp); + error = devfs_allocv(de, dvp->v_mount, LK_EXCLUSIVE, vpp); return (error); notfound: sx_xunlock(&dmp->dm_lock); @@ -951,7 +956,7 @@ devfs_open(struct vop_open_args *ap) struct vnode *vp = ap->a_vp; struct cdev *dev = vp->v_rdev; struct file *fp = ap->a_fp; - int error; + int error, vlocked; struct cdevsw *dsw; struct file *fpop; @@ -969,6 +974,7 @@ devfs_open(struct vop_open_args *ap) if (dsw == NULL) return (ENXIO); + vlocked = VOP_ISLOCKED(vp); VOP_UNLOCK(vp, 0); fpop = td->td_fpop; @@ -983,18 +989,15 @@ devfs_open(struct vop_open_args *ap) error = dsw->d_open(dev, ap->a_mode, S_IFCHR, td); td->td_fpop = fpop; - vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); - + vn_lock(vp, vlocked | LK_RETRY); dev_relthread(dev); - if (error) return (error); #if 0 /* /dev/console */ - KASSERT(fp != NULL, - ("Could not vnode bypass device on NULL fp")); + KASSERT(fp != NULL, ("Could not vnode bypass device on NULL fp")); #else - if(fp == NULL) + if (fp == NULL) return (error); #endif if (fp->f_ops == &badfileops) @@ -1487,7 +1490,7 @@ devfs_symlink(struct vop_symlink_args *a mac_devfs_create_symlink(ap->a_cnp->cn_cred, dmp->dm_mount, dd, de); #endif TAILQ_INSERT_TAIL(&dd->de_dlist, de, de_list); - return (devfs_allocv(de, ap->a_dvp->v_mount, ap->a_vpp)); + return (devfs_allocv(de, ap->a_dvp->v_mount, LK_EXCLUSIVE, ap->a_vpp)); } static int From owner-svn-src-stable@FreeBSD.ORG Sun Sep 5 14:27:55 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E8FF41065670; Sun, 5 Sep 2010 14:27:55 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D66C78FC1A; Sun, 5 Sep 2010 14:27:55 +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 o85ERtTl083469; Sun, 5 Sep 2010 14:27:55 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o85ERti5083459; Sun, 5 Sep 2010 14:27:55 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201009051427.o85ERti5083459@svn.freebsd.org> From: Konstantin Belousov Date: Sun, 5 Sep 2010 14:27:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212229 - in stable/8/sys: fs/devfs kern sys vm X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Sep 2010 14:27:56 -0000 Author: kib Date: Sun Sep 5 14:27:55 2010 New Revision: 212229 URL: http://svn.freebsd.org/changeset/base/212229 Log: MFC r210923: Add new make_dev_p(9) flag MAKEDEV_ETERNAL to inform devfs that created cdev will never be destroyed. Propagate the flag to devfs vnodes as VV_ETERNVALDEV. Use the flags to avoid acquiring devmtx and taking a thread reference on such nodes. Modified: stable/8/sys/fs/devfs/devfs_rule.c stable/8/sys/fs/devfs/devfs_vnops.c stable/8/sys/kern/kern_conf.c stable/8/sys/kern/tty.c stable/8/sys/kern/vfs_bio.c stable/8/sys/sys/conf.h stable/8/sys/sys/vnode.h stable/8/sys/vm/device_pager.c stable/8/sys/vm/vm_mmap.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/fs/devfs/devfs_rule.c ============================================================================== --- stable/8/sys/fs/devfs/devfs_rule.c Sun Sep 5 14:20:34 2010 (r212228) +++ stable/8/sys/fs/devfs/devfs_rule.c Sun Sep 5 14:27:55 2010 (r212229) @@ -528,6 +528,7 @@ devfs_rule_match(struct devfs_krule *dk, struct devfs_rule *dr = &dk->dk_rule; struct cdev *dev; struct cdevsw *dsw; + int ref; dev = devfs_rule_getdev(de); /* @@ -545,14 +546,14 @@ devfs_rule_match(struct devfs_krule *dk, if (dr->dr_icond & DRC_DSWFLAGS) { if (dev == NULL) return (0); - dsw = dev_refthread(dev); + dsw = dev_refthread(dev, &ref); if (dsw == NULL) return (0); if ((dsw->d_flags & dr->dr_dswflags) == 0) { - dev_relthread(dev); + dev_relthread(dev, ref); return (0); } - dev_relthread(dev); + dev_relthread(dev, ref); } if (dr->dr_icond & DRC_PATHPTRN) if (!devfs_rule_matchpath(dk, de)) Modified: stable/8/sys/fs/devfs/devfs_vnops.c ============================================================================== --- stable/8/sys/fs/devfs/devfs_vnops.c Sun Sep 5 14:20:34 2010 (r212228) +++ stable/8/sys/fs/devfs/devfs_vnops.c Sun Sep 5 14:27:55 2010 (r212229) @@ -82,13 +82,14 @@ struct mtx cdevpriv_mtx; MTX_SYSINIT(cdevpriv_mtx, &cdevpriv_mtx, "cdevpriv lock", MTX_DEF); static int -devfs_fp_check(struct file *fp, struct cdev **devp, struct cdevsw **dswp) +devfs_fp_check(struct file *fp, struct cdev **devp, struct cdevsw **dswp, + int *ref) { - *dswp = devvn_refthread(fp->f_vnode, devp); + *dswp = devvn_refthread(fp->f_vnode, devp, ref); if (*devp != fp->f_data) { if (*dswp != NULL) - dev_relthread(*devp); + dev_relthread(*devp, *ref); return (ENXIO); } KASSERT((*devp)->si_refcount > 0, @@ -401,6 +402,8 @@ devfs_allocv(struct devfs_dirent *de, st vp->v_vflag |= VV_ISTTY; dev_unlock(); VI_UNLOCK(vp); + if ((dev->si_flags & SI_ETERNAL) != 0) + vp->v_vflag |= VV_ETERNALDEV; vp->v_op = &devfs_specops; } else if (de->de_dirent->d_type == DT_DIR) { vp->v_type = VDIR; @@ -465,7 +468,7 @@ devfs_close(struct vop_close_args *ap) struct thread *td = ap->a_td; struct cdev *dev = vp->v_rdev; struct cdevsw *dsw; - int vp_locked, error; + int vp_locked, error, ref; /* * XXX: Don't call d_close() if we were called because of @@ -507,7 +510,7 @@ devfs_close(struct vop_close_args *ap) * sum of the reference counts on all the aliased * vnodes descends to one, we are on last close. */ - dsw = dev_refthread(dev); + dsw = dev_refthread(dev, &ref); if (dsw == NULL) return (ENXIO); VI_LOCK(vp); @@ -517,7 +520,7 @@ devfs_close(struct vop_close_args *ap) /* Keep device updated on status. */ } else if (count_dev(dev) > 1) { VI_UNLOCK(vp); - dev_relthread(dev); + dev_relthread(dev, ref); return (0); } vholdl(vp); @@ -527,7 +530,7 @@ devfs_close(struct vop_close_args *ap) KASSERT(dev->si_refcount > 0, ("devfs_close() on un-referenced struct cdev *(%s)", devtoname(dev))); error = dsw->d_close(dev, ap->a_fflag, S_IFCHR, td); - dev_relthread(dev); + dev_relthread(dev, ref); vn_lock(vp, vp_locked | LK_RETRY); vdrop(vp); return (error); @@ -645,20 +648,20 @@ devfs_ioctl_f(struct file *fp, u_long co struct cdevsw *dsw; struct vnode *vp; struct vnode *vpold; - int error, i; + int error, i, ref; const char *p; struct fiodgname_arg *fgn; struct file *fpop; fpop = td->td_fpop; - error = devfs_fp_check(fp, &dev, &dsw); + error = devfs_fp_check(fp, &dev, &dsw, &ref); if (error) return (error); if (com == FIODTYPE) { *(int *)data = dsw->d_flags & D_TYPEMASK; td->td_fpop = fpop; - dev_relthread(dev); + dev_relthread(dev, ref); return (0); } else if (com == FIODGNAME) { fgn = data; @@ -669,12 +672,12 @@ devfs_ioctl_f(struct file *fp, u_long co else error = copyout(p, fgn->buf, i); td->td_fpop = fpop; - dev_relthread(dev); + dev_relthread(dev, ref); return (error); } error = dsw->d_ioctl(dev, com, data, fp->f_flag, td); td->td_fpop = NULL; - dev_relthread(dev); + dev_relthread(dev, ref); if (error == ENOIOCTL) error = ENOTTY; if (error == 0 && com == TIOCSCTTY) { @@ -708,18 +711,18 @@ devfs_kqfilter_f(struct file *fp, struct { struct cdev *dev; struct cdevsw *dsw; - int error; + int error, ref; struct file *fpop; struct thread *td; td = curthread; fpop = td->td_fpop; - error = devfs_fp_check(fp, &dev, &dsw); + error = devfs_fp_check(fp, &dev, &dsw, &ref); if (error) return (error); error = dsw->d_kqfilter(dev, kn); td->td_fpop = fpop; - dev_relthread(dev); + dev_relthread(dev, ref); return (error); } @@ -956,7 +959,7 @@ devfs_open(struct vop_open_args *ap) struct vnode *vp = ap->a_vp; struct cdev *dev = vp->v_rdev; struct file *fp = ap->a_fp; - int error, vlocked; + int error, ref, vlocked; struct cdevsw *dsw; struct file *fpop; @@ -970,7 +973,7 @@ devfs_open(struct vop_open_args *ap) if (dev->si_iosize_max == 0) dev->si_iosize_max = DFLTPHYS; - dsw = dev_refthread(dev); + dsw = dev_refthread(dev, &ref); if (dsw == NULL) return (ENXIO); @@ -990,7 +993,7 @@ devfs_open(struct vop_open_args *ap) td->td_fpop = fpop; vn_lock(vp, vlocked | LK_RETRY); - dev_relthread(dev); + dev_relthread(dev, ref); if (error) return (error); @@ -1033,16 +1036,16 @@ devfs_poll_f(struct file *fp, int events { struct cdev *dev; struct cdevsw *dsw; - int error; + int error, ref; struct file *fpop; fpop = td->td_fpop; - error = devfs_fp_check(fp, &dev, &dsw); + error = devfs_fp_check(fp, &dev, &dsw, &ref); if (error) return (poll_no_poll(events)); error = dsw->d_poll(dev, events, td); td->td_fpop = fpop; - dev_relthread(dev); + dev_relthread(dev, ref); return(error); } @@ -1062,12 +1065,12 @@ static int devfs_read_f(struct file *fp, struct uio *uio, struct ucred *cred, int flags, struct thread *td) { struct cdev *dev; - int ioflag, error, resid; + int ioflag, error, ref, resid; struct cdevsw *dsw; struct file *fpop; fpop = td->td_fpop; - error = devfs_fp_check(fp, &dev, &dsw); + error = devfs_fp_check(fp, &dev, &dsw, &ref); if (error) return (error); resid = uio->uio_resid; @@ -1082,7 +1085,7 @@ devfs_read_f(struct file *fp, struct uio if (uio->uio_resid != resid || (error == 0 && resid != 0)) vfs_timestamp(&dev->si_atime); td->td_fpop = fpop; - dev_relthread(dev); + dev_relthread(dev, ref); if ((flags & FOF_OFFSET) == 0) fp->f_offset = uio->uio_offset; @@ -1505,12 +1508,12 @@ static int devfs_write_f(struct file *fp, struct uio *uio, struct ucred *cred, int flags, struct thread *td) { struct cdev *dev; - int error, ioflag, resid; + int error, ioflag, ref, resid; struct cdevsw *dsw; struct file *fpop; fpop = td->td_fpop; - error = devfs_fp_check(fp, &dev, &dsw); + error = devfs_fp_check(fp, &dev, &dsw, &ref); if (error) return (error); KASSERT(uio->uio_td == td, ("uio_td %p is not td %p", uio->uio_td, td)); @@ -1528,7 +1531,7 @@ devfs_write_f(struct file *fp, struct ui dev->si_mtime = dev->si_ctime; } td->td_fpop = fpop; - dev_relthread(dev); + dev_relthread(dev, ref); if ((flags & FOF_OFFSET) == 0) fp->f_offset = uio->uio_offset; Modified: stable/8/sys/kern/kern_conf.c ============================================================================== --- stable/8/sys/kern/kern_conf.c Sun Sep 5 14:20:34 2010 (r212228) +++ stable/8/sys/kern/kern_conf.c Sun Sep 5 14:27:55 2010 (r212229) @@ -177,12 +177,16 @@ dev_rel(struct cdev *dev) } struct cdevsw * -dev_refthread(struct cdev *dev) +dev_refthread(struct cdev *dev, int *ref) { struct cdevsw *csw; struct cdev_priv *cdp; mtx_assert(&devmtx, MA_NOTOWNED); + if ((dev->si_flags & SI_ETERNAL) != 0) { + *ref = 0; + return (dev->si_devsw); + } dev_lock(); csw = dev->si_devsw; if (csw != NULL) { @@ -193,36 +197,59 @@ dev_refthread(struct cdev *dev) csw = NULL; } dev_unlock(); + *ref = 1; return (csw); } struct cdevsw * -devvn_refthread(struct vnode *vp, struct cdev **devp) +devvn_refthread(struct vnode *vp, struct cdev **devp, int *ref) { struct cdevsw *csw; struct cdev_priv *cdp; + struct cdev *dev; mtx_assert(&devmtx, MA_NOTOWNED); + if ((vp->v_vflag & VV_ETERNALDEV) != 0) { + dev = vp->v_rdev; + if (dev == NULL) + return (NULL); + KASSERT((dev->si_flags & SI_ETERNAL) != 0, + ("Not eternal cdev")); + *ref = 0; + csw = dev->si_devsw; + KASSERT(csw != NULL, ("Eternal cdev is destroyed")); + *devp = dev; + return (csw); + } + csw = NULL; dev_lock(); - *devp = vp->v_rdev; - if (*devp != NULL) { - cdp = cdev2priv(*devp); - if ((cdp->cdp_flags & CDP_SCHED_DTR) == 0) { - csw = (*devp)->si_devsw; - if (csw != NULL) - (*devp)->si_threadcount++; - } + dev = vp->v_rdev; + if (dev == NULL) { + dev_unlock(); + return (NULL); + } + cdp = cdev2priv(dev); + if ((cdp->cdp_flags & CDP_SCHED_DTR) == 0) { + csw = dev->si_devsw; + if (csw != NULL) + dev->si_threadcount++; } dev_unlock(); + if (csw != NULL) { + *devp = dev; + *ref = 1; + } return (csw); } void -dev_relthread(struct cdev *dev) +dev_relthread(struct cdev *dev, int ref) { mtx_assert(&devmtx, MA_NOTOWNED); + if (!ref) + return; dev_lock(); KASSERT(dev->si_threadcount > 0, ("%s threadcount is wrong", dev->si_name)); @@ -325,15 +352,15 @@ static int giant_open(struct cdev *dev, int oflags, int devtype, struct thread *td) { struct cdevsw *dsw; - int retval; + int ref, retval; - dsw = dev_refthread(dev); + dsw = dev_refthread(dev, &ref); if (dsw == NULL) return (ENXIO); mtx_lock(&Giant); retval = dsw->d_gianttrick->d_open(dev, oflags, devtype, td); mtx_unlock(&Giant); - dev_relthread(dev); + dev_relthread(dev, ref); return (retval); } @@ -341,15 +368,15 @@ static int giant_fdopen(struct cdev *dev, int oflags, struct thread *td, struct file *fp) { struct cdevsw *dsw; - int retval; + int ref, retval; - dsw = dev_refthread(dev); + dsw = dev_refthread(dev, &ref); if (dsw == NULL) return (ENXIO); mtx_lock(&Giant); retval = dsw->d_gianttrick->d_fdopen(dev, oflags, td, fp); mtx_unlock(&Giant); - dev_relthread(dev); + dev_relthread(dev, ref); return (retval); } @@ -357,15 +384,15 @@ static int giant_close(struct cdev *dev, int fflag, int devtype, struct thread *td) { struct cdevsw *dsw; - int retval; + int ref, retval; - dsw = dev_refthread(dev); + dsw = dev_refthread(dev, &ref); if (dsw == NULL) return (ENXIO); mtx_lock(&Giant); retval = dsw->d_gianttrick->d_close(dev, fflag, devtype, td); mtx_unlock(&Giant); - dev_relthread(dev); + dev_relthread(dev, ref); return (retval); } @@ -374,9 +401,10 @@ giant_strategy(struct bio *bp) { struct cdevsw *dsw; struct cdev *dev; + int ref; dev = bp->bio_dev; - dsw = dev_refthread(dev); + dsw = dev_refthread(dev, &ref); if (dsw == NULL) { biofinish(bp, NULL, ENXIO); return; @@ -384,22 +412,22 @@ giant_strategy(struct bio *bp) mtx_lock(&Giant); dsw->d_gianttrick->d_strategy(bp); mtx_unlock(&Giant); - dev_relthread(dev); + dev_relthread(dev, ref); } static int giant_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct thread *td) { struct cdevsw *dsw; - int retval; + int ref, retval; - dsw = dev_refthread(dev); + dsw = dev_refthread(dev, &ref); if (dsw == NULL) return (ENXIO); mtx_lock(&Giant); retval = dsw->d_gianttrick->d_ioctl(dev, cmd, data, fflag, td); mtx_unlock(&Giant); - dev_relthread(dev); + dev_relthread(dev, ref); return (retval); } @@ -407,15 +435,15 @@ static int giant_read(struct cdev *dev, struct uio *uio, int ioflag) { struct cdevsw *dsw; - int retval; + int ref, retval; - dsw = dev_refthread(dev); + dsw = dev_refthread(dev, &ref); if (dsw == NULL) return (ENXIO); mtx_lock(&Giant); retval = dsw->d_gianttrick->d_read(dev, uio, ioflag); mtx_unlock(&Giant); - dev_relthread(dev); + dev_relthread(dev, ref); return (retval); } @@ -423,15 +451,15 @@ static int giant_write(struct cdev *dev, struct uio *uio, int ioflag) { struct cdevsw *dsw; - int retval; + int ref, retval; - dsw = dev_refthread(dev); + dsw = dev_refthread(dev, &ref); if (dsw == NULL) return (ENXIO); mtx_lock(&Giant); retval = dsw->d_gianttrick->d_write(dev, uio, ioflag); mtx_unlock(&Giant); - dev_relthread(dev); + dev_relthread(dev, ref); return (retval); } @@ -439,15 +467,15 @@ static int giant_poll(struct cdev *dev, int events, struct thread *td) { struct cdevsw *dsw; - int retval; + int ref, retval; - dsw = dev_refthread(dev); + dsw = dev_refthread(dev, &ref); if (dsw == NULL) return (ENXIO); mtx_lock(&Giant); retval = dsw->d_gianttrick->d_poll(dev, events, td); mtx_unlock(&Giant); - dev_relthread(dev); + dev_relthread(dev, ref); return (retval); } @@ -455,15 +483,15 @@ static int giant_kqfilter(struct cdev *dev, struct knote *kn) { struct cdevsw *dsw; - int retval; + int ref, retval; - dsw = dev_refthread(dev); + dsw = dev_refthread(dev, &ref); if (dsw == NULL) return (ENXIO); mtx_lock(&Giant); retval = dsw->d_gianttrick->d_kqfilter(dev, kn); mtx_unlock(&Giant); - dev_relthread(dev); + dev_relthread(dev, ref); return (retval); } @@ -472,9 +500,9 @@ giant_mmap(struct cdev *dev, vm_offset_t vm_memattr_t *memattr) { struct cdevsw *dsw; - int retval; + int ref, retval; - dsw = dev_refthread(dev); + dsw = dev_refthread(dev, &ref); if (dsw == NULL) return (ENXIO); mtx_lock(&Giant); @@ -484,7 +512,7 @@ giant_mmap(struct cdev *dev, vm_offset_t else retval = dsw->d_gianttrick->d_mmap(dev, offset, paddr, nprot); mtx_unlock(&Giant); - dev_relthread(dev); + dev_relthread(dev, ref); return (retval); } @@ -493,16 +521,16 @@ giant_mmap_single(struct cdev *dev, vm_o vm_object_t *object, int nprot) { struct cdevsw *dsw; - int retval; + int ref, retval; - dsw = dev_refthread(dev); + dsw = dev_refthread(dev, &ref); if (dsw == NULL) return (ENXIO); mtx_lock(&Giant); retval = dsw->d_gianttrick->d_mmap_single(dev, offset, size, object, nprot); mtx_unlock(&Giant); - dev_relthread(dev); + dev_relthread(dev, ref); return (retval); } @@ -682,6 +710,8 @@ make_dev_credv(int flags, struct cdev ** dev = newdev(devsw, unit, dev); if (flags & MAKEDEV_REF) dev_refl(dev); + if (flags & MAKEDEV_ETERNAL) + dev->si_flags |= SI_ETERNAL; if (dev->si_flags & SI_CHEAPCLONE && dev->si_flags & SI_NAMED) { /* @@ -846,6 +876,9 @@ destroy_devl(struct cdev *dev) mtx_assert(&devmtx, MA_OWNED); KASSERT(dev->si_flags & SI_NAMED, ("WARNING: Driver mistake: destroy_dev on %d\n", dev2unit(dev))); + KASSERT((dev->si_flags & SI_ETERNAL) == 0, + ("WARNING: Driver mistake: destroy_dev on eternal %d\n", + dev2unit(dev))); devfs_destroy(dev); Modified: stable/8/sys/kern/tty.c ============================================================================== --- stable/8/sys/kern/tty.c Sun Sep 5 14:20:34 2010 (r212228) +++ stable/8/sys/kern/tty.c Sun Sep 5 14:27:55 2010 (r212229) @@ -1777,7 +1777,7 @@ ttyhook_register(struct tty **rtp, struc struct cdev *dev; struct cdevsw *cdp; struct filedesc *fdp; - int error; + int error, ref; /* Validate the file descriptor. */ if ((fdp = p->p_fd) == NULL) @@ -1803,7 +1803,7 @@ ttyhook_register(struct tty **rtp, struc } /* Make sure it is a TTY. */ - cdp = devvn_refthread(fp->f_vnode, &dev); + cdp = devvn_refthread(fp->f_vnode, &dev, &ref); if (cdp == NULL) { error = ENXIO; goto done1; @@ -1839,7 +1839,7 @@ ttyhook_register(struct tty **rtp, struc th->th_rint = ttyhook_defrint; done3: tty_unlock(tp); -done2: dev_relthread(dev); +done2: dev_relthread(dev, ref); done1: fdrop(fp, curthread); return (error); } Modified: stable/8/sys/kern/vfs_bio.c ============================================================================== --- stable/8/sys/kern/vfs_bio.c Sun Sep 5 14:20:34 2010 (r212228) +++ stable/8/sys/kern/vfs_bio.c Sun Sep 5 14:27:55 2010 (r212229) @@ -3195,6 +3195,7 @@ dev_strategy(struct cdev *dev, struct bu { struct cdevsw *csw; struct bio *bip; + int ref; if ((!bp->b_iocmd) || (bp->b_iocmd & (bp->b_iocmd - 1))) panic("b_iocmd botch"); @@ -3216,7 +3217,7 @@ dev_strategy(struct cdev *dev, struct bu KASSERT(dev->si_refcount > 0, ("dev_strategy on un-referenced struct cdev *(%s)", devtoname(dev))); - csw = dev_refthread(dev); + csw = dev_refthread(dev, &ref); if (csw == NULL) { g_destroy_bio(bip); bp->b_error = ENXIO; @@ -3225,7 +3226,7 @@ dev_strategy(struct cdev *dev, struct bu return; } (*csw->d_strategy)(bip); - dev_relthread(dev); + dev_relthread(dev, ref); } /* Modified: stable/8/sys/sys/conf.h ============================================================================== --- stable/8/sys/sys/conf.h Sun Sep 5 14:20:34 2010 (r212228) +++ stable/8/sys/sys/conf.h Sun Sep 5 14:27:55 2010 (r212229) @@ -54,6 +54,7 @@ struct file; struct cdev { void *__si_reserved; u_int si_flags; +#define SI_ETERNAL 0x0001 /* never destroyed */ #define SI_ALIAS 0x0002 /* carrier of alias name */ #define SI_NAMED 0x0004 /* make_dev{_alias} has been called */ #define SI_CHEAPCLONE 0x0008 /* can be removed_dev'ed when vnode reclaims */ @@ -258,9 +259,9 @@ int destroy_dev_sched(struct cdev *dev); int destroy_dev_sched_cb(struct cdev *dev, void (*cb)(void *), void *arg); void destroy_dev_drain(struct cdevsw *csw); void drain_dev_clone_events(void); -struct cdevsw *dev_refthread(struct cdev *_dev); -struct cdevsw *devvn_refthread(struct vnode *vp, struct cdev **devp); -void dev_relthread(struct cdev *_dev); +struct cdevsw *dev_refthread(struct cdev *_dev, int *_ref); +struct cdevsw *devvn_refthread(struct vnode *vp, struct cdev **devp, int *_ref); +void dev_relthread(struct cdev *_dev, int _ref); void dev_depends(struct cdev *_pdev, struct cdev *_cdev); void dev_ref(struct cdev *dev); void dev_refl(struct cdev *dev); @@ -271,10 +272,11 @@ struct cdev *make_dev(struct cdevsw *_de struct cdev *make_dev_cred(struct cdevsw *_devsw, int _unit, struct ucred *_cr, uid_t _uid, gid_t _gid, int _perms, const char *_fmt, ...) __printflike(7, 8); -#define MAKEDEV_REF 0x1 -#define MAKEDEV_WHTOUT 0x2 -#define MAKEDEV_NOWAIT 0x4 -#define MAKEDEV_WAITOK 0x8 +#define MAKEDEV_REF 0x01 +#define MAKEDEV_WHTOUT 0x02 +#define MAKEDEV_NOWAIT 0x04 +#define MAKEDEV_WAITOK 0x08 +#define MAKEDEV_ETERNAL 0x10 struct cdev *make_dev_credf(int _flags, struct cdevsw *_devsw, int _unit, struct ucred *_cr, uid_t _uid, gid_t _gid, int _mode, @@ -288,6 +290,12 @@ void dev_lock(void); void dev_unlock(void); void setconf(void); +#ifdef KLD_MODULE +#define MAKEDEV_ETERNAL_KLD 0 +#else +#define MAKEDEV_ETERNAL_KLD MAKEDEV_ETERNAL +#endif + #define dev2unit(d) ((d)->si_drv0) typedef void (*cdevpriv_dtr_t)(void *data); Modified: stable/8/sys/sys/vnode.h ============================================================================== --- stable/8/sys/sys/vnode.h Sun Sep 5 14:20:34 2010 (r212228) +++ stable/8/sys/sys/vnode.h Sun Sep 5 14:27:55 2010 (r212229) @@ -243,6 +243,7 @@ struct xvnode { #define VV_ROOT 0x0001 /* root of its filesystem */ #define VV_ISTTY 0x0002 /* vnode represents a tty */ #define VV_NOSYNC 0x0004 /* unlinked, stop syncing */ +#define VV_ETERNALDEV 0x0008 /* device that is never destroyed */ #define VV_CACHEDLABEL 0x0010 /* Vnode has valid cached MAC label */ #define VV_TEXT 0x0020 /* vnode is a pure text prototype */ #define VV_COPYONWRITE 0x0040 /* vnode is doing copy-on-write */ Modified: stable/8/sys/vm/device_pager.c ============================================================================== --- stable/8/sys/vm/device_pager.c Sun Sep 5 14:20:34 2010 (r212228) +++ stable/8/sys/vm/device_pager.c Sun Sep 5 14:27:55 2010 (r212229) @@ -119,6 +119,7 @@ dev_pager_alloc(void *handle, vm_ooffset vm_offset_t off; vm_memattr_t dummy; struct cdevsw *csw; + int ref; /* * Offset should be page aligned. @@ -133,7 +134,7 @@ dev_pager_alloc(void *handle, vm_ooffset * Make sure this device can be mapped. */ dev = handle; - csw = dev_refthread(dev); + csw = dev_refthread(dev, &ref); if (csw == NULL) return (NULL); @@ -146,7 +147,7 @@ dev_pager_alloc(void *handle, vm_ooffset npages = OFF_TO_IDX(size); for (off = foff; npages--; off += PAGE_SIZE) if (dev_mmap(csw, dev, off, &paddr, (int)prot, &dummy) != 0) { - dev_relthread(dev); + dev_relthread(dev, ref); return (NULL); } @@ -188,7 +189,7 @@ dev_pager_alloc(void *handle, vm_ooffset object->size = pindex; } mtx_unlock(&dev_pager_mtx); - dev_relthread(dev); + dev_relthread(dev, ref); vm_object_deallocate(object1); return (object); } @@ -225,7 +226,7 @@ dev_pager_getpages(object, m, count, req vm_page_t m_paddr, page; vm_memattr_t memattr; struct cdev *dev; - int i, ret; + int i, ref, ret; struct cdevsw *csw; struct thread *td; struct file *fpop; @@ -236,7 +237,7 @@ dev_pager_getpages(object, m, count, req offset = page->pindex; memattr = object->memattr; VM_OBJECT_UNLOCK(object); - csw = dev_refthread(dev); + csw = dev_refthread(dev, &ref); if (csw == NULL) panic("dev_pager_getpage: no cdevsw"); td = curthread; @@ -246,7 +247,7 @@ dev_pager_getpages(object, m, count, req PROT_READ, &memattr); KASSERT(ret == 0, ("dev_pager_getpage: map function returns error")); td->td_fpop = fpop; - dev_relthread(dev); + dev_relthread(dev, ref); /* If "paddr" is a real page, perform a sanity check on "memattr". */ if ((m_paddr = vm_phys_paddr_to_vm_page(paddr)) != NULL && pmap_page_get_memattr(m_paddr) != memattr) { Modified: stable/8/sys/vm/vm_mmap.c ============================================================================== --- stable/8/sys/vm/vm_mmap.c Sun Sep 5 14:20:34 2010 (r212228) +++ stable/8/sys/vm/vm_mmap.c Sun Sep 5 14:27:55 2010 (r212229) @@ -1243,15 +1243,15 @@ vm_mmap_cdev(struct thread *td, vm_size_ { vm_object_t obj; struct cdevsw *dsw; - int error, flags; + int error, flags, ref; flags = *flagsp; - dsw = dev_refthread(cdev); + dsw = dev_refthread(cdev, &ref); if (dsw == NULL) return (ENXIO); if (dsw->d_flags & D_MMAP_ANON) { - dev_relthread(cdev); + dev_relthread(cdev, ref); *maxprotp = VM_PROT_ALL; *flagsp |= MAP_ANON; return (0); @@ -1261,11 +1261,11 @@ vm_mmap_cdev(struct thread *td, vm_size_ */ if ((*maxprotp & VM_PROT_WRITE) == 0 && (prot & PROT_WRITE) != 0) { - dev_relthread(cdev); + dev_relthread(cdev, ref); return (EACCES); } if (flags & (MAP_PRIVATE|MAP_COPY)) { - dev_relthread(cdev); + dev_relthread(cdev, ref); return (EINVAL); } /* @@ -1275,7 +1275,7 @@ vm_mmap_cdev(struct thread *td, vm_size_ #ifdef MAC_XXX error = mac_cdev_check_mmap(td->td_ucred, cdev, prot); if (error != 0) { - dev_relthread(cdev); + dev_relthread(cdev, ref); return (error); } #endif @@ -1289,7 +1289,7 @@ vm_mmap_cdev(struct thread *td, vm_size_ * XXX assumes VM_PROT_* == PROT_* */ error = dsw->d_mmap_single(cdev, foff, objsize, objp, (int)prot); - dev_relthread(cdev); + dev_relthread(cdev, ref); if (error != ENODEV) return (error); obj = vm_pager_allocate(OBJT_DEVICE, cdev, objsize, prot, *foff, From owner-svn-src-stable@FreeBSD.ORG Sun Sep 5 14:31:59 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 628F81065697; Sun, 5 Sep 2010 14:31:59 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 372EC8FC15; Sun, 5 Sep 2010 14:31:59 +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 o85EVxDa083740; Sun, 5 Sep 2010 14:31:59 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o85EVxNY083738; Sun, 5 Sep 2010 14:31:59 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201009051431.o85EVxNY083738@svn.freebsd.org> From: Konstantin Belousov Date: Sun, 5 Sep 2010 14:31:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212230 - stable/8/sys/kern X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Sep 2010 14:31:59 -0000 Author: kib Date: Sun Sep 5 14:31:58 2010 New Revision: 212230 URL: http://svn.freebsd.org/changeset/base/212230 Log: MFC r210924: Add "show cdev" ddb command. Modified: stable/8/sys/kern/kern_conf.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/kern/kern_conf.c ============================================================================== --- stable/8/sys/kern/kern_conf.c Sun Sep 5 14:27:55 2010 (r212229) +++ stable/8/sys/kern/kern_conf.c Sun Sep 5 14:31:58 2010 (r212230) @@ -1235,3 +1235,71 @@ devdtr_init(void *dummy __unused) } SYSINIT(devdtr, SI_SUB_DEVFS, SI_ORDER_SECOND, devdtr_init, NULL); + +#include "opt_ddb.h" +#ifdef DDB +#include + +#include + +DB_SHOW_COMMAND(cdev, db_show_cdev) +{ + struct cdev_priv *cdp; + struct cdev *dev; + u_int flags; + char buf[512]; + + if (!have_addr) { + TAILQ_FOREACH(cdp, &cdevp_list, cdp_list) { + dev = &cdp->cdp_c; + db_printf("%s %p\n", dev->si_name, dev); + if (db_pager_quit) + break; + } + return; + } + + dev = (struct cdev *)addr; + cdp = cdev2priv(dev); + db_printf("dev %s ref %d use %ld thr %ld inuse %u fdpriv %p\n", + dev->si_name, dev->si_refcount, dev->si_usecount, + dev->si_threadcount, cdp->cdp_inuse, cdp->cdp_fdpriv.lh_first); + db_printf("devsw %p si_drv0 %d si_drv1 %p si_drv2 %p\n", + dev->si_devsw, dev->si_drv0, dev->si_drv1, dev->si_drv2); + flags = dev->si_flags; +#define SI_FLAG(flag) do { \ + if (flags & (flag)) { \ + if (buf[0] != '\0') \ + strlcat(buf, ", ", sizeof(buf)); \ + strlcat(buf, (#flag) + 3, sizeof(buf)); \ + flags &= ~(flag); \ + } \ +} while (0) + buf[0] = '\0'; + SI_FLAG(SI_ETERNAL); + SI_FLAG(SI_ALIAS); + SI_FLAG(SI_NAMED); + SI_FLAG(SI_CHEAPCLONE); + SI_FLAG(SI_CHILD); + SI_FLAG(SI_DEVOPEN); + SI_FLAG(SI_CONSOPEN); + SI_FLAG(SI_DUMPDEV); + SI_FLAG(SI_CANDELETE); + SI_FLAG(SI_CLONELIST); + db_printf("si_flags %s\n", buf); + + flags = cdp->cdp_flags; +#define CDP_FLAG(flag) do { \ + if (flags & (flag)) { \ + if (buf[0] != '\0') \ + strlcat(buf, ", ", sizeof(buf)); \ + strlcat(buf, (#flag) + 4, sizeof(buf)); \ + flags &= ~(flag); \ + } \ +} while (0) + buf[0] = '\0'; + CDP_FLAG(CDP_ACTIVE); + CDP_FLAG(CDP_SCHED_DTR); + db_printf("cdp_flags %s\n", buf); +} +#endif From owner-svn-src-stable@FreeBSD.ORG Sun Sep 5 14:35:27 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4C65010656D9; Sun, 5 Sep 2010 14:35:27 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 3B4CE8FC1A; Sun, 5 Sep 2010 14:35:27 +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 o85EZRwl083950; Sun, 5 Sep 2010 14:35:27 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o85EZRRg083948; Sun, 5 Sep 2010 14:35:27 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201009051435.o85EZRRg083948@svn.freebsd.org> From: Konstantin Belousov Date: Sun, 5 Sep 2010 14:35:27 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212231 - stable/8/sys/fs/devfs X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Sep 2010 14:35:27 -0000 Author: kib Date: Sun Sep 5 14:35:26 2010 New Revision: 212231 URL: http://svn.freebsd.org/changeset/base/212231 Log: MFC r210925: Enable shared lookups and externed shared ops for devfs. Modified: stable/8/sys/fs/devfs/devfs_vfsops.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/fs/devfs/devfs_vfsops.c ============================================================================== --- stable/8/sys/fs/devfs/devfs_vfsops.c Sun Sep 5 14:31:58 2010 (r212230) +++ stable/8/sys/fs/devfs/devfs_vfsops.c Sun Sep 5 14:35:26 2010 (r212231) @@ -81,7 +81,8 @@ devfs_mount(struct mount *mp) MNT_ILOCK(mp); mp->mnt_flag |= MNT_LOCAL; - mp->mnt_kern_flag |= MNTK_MPSAFE; + mp->mnt_kern_flag |= MNTK_MPSAFE | MNTK_LOOKUP_SHARED | + MNTK_EXTENDED_SHARED; #ifdef MAC mp->mnt_flag |= MNT_MULTILABEL; #endif From owner-svn-src-stable@FreeBSD.ORG Sun Sep 5 14:37:29 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 82EAF10656CC; Sun, 5 Sep 2010 14:37:29 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 71FC08FC19; Sun, 5 Sep 2010 14:37:29 +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 o85EbTWT084091; Sun, 5 Sep 2010 14:37:29 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o85EbTut084089; Sun, 5 Sep 2010 14:37:29 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201009051437.o85EbTut084089@svn.freebsd.org> From: Konstantin Belousov Date: Sun, 5 Sep 2010 14:37:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212232 - stable/8/sys/dev/null X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Sep 2010 14:37:29 -0000 Author: kib Date: Sun Sep 5 14:37:29 2010 New Revision: 212232 URL: http://svn.freebsd.org/changeset/base/212232 Log: MFC r210926: Mark /dev/zero and /dev/null as eternal. Modified: stable/8/sys/dev/null/null.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/dev/null/null.c ============================================================================== --- stable/8/sys/dev/null/null.c Sun Sep 5 14:35:26 2010 (r212231) +++ stable/8/sys/dev/null/null.c Sun Sep 5 14:37:29 2010 (r212232) @@ -112,10 +112,10 @@ null_modevent(module_t mod __unused, int if (bootverbose) printf("null: \n"); zbuf = (void *)malloc(PAGE_SIZE, M_TEMP, M_WAITOK | M_ZERO); - null_dev = make_dev(&null_cdevsw, 0, UID_ROOT, GID_WHEEL, - 0666, "null"); - zero_dev = make_dev(&zero_cdevsw, 0, UID_ROOT, GID_WHEEL, - 0666, "zero"); + null_dev = make_dev_credf(MAKEDEV_ETERNAL_KLD, &null_cdevsw, 0, + NULL, UID_ROOT, GID_WHEEL, 0666, "null"); + zero_dev = make_dev_credf(MAKEDEV_ETERNAL_KLD, &zero_cdevsw, 0, + NULL, UID_ROOT, GID_WHEEL, 0666, "zero"); break; case MOD_UNLOAD: From owner-svn-src-stable@FreeBSD.ORG Mon Sep 6 07:24:44 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 13F9110656A6; Mon, 6 Sep 2010 07:24:44 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 023F88FC0A; Mon, 6 Sep 2010 07:24:44 +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 o867OhJR021822; Mon, 6 Sep 2010 07:24:43 GMT (envelope-from avg@svn.freebsd.org) Received: (from avg@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o867OhJ5021820; Mon, 6 Sep 2010 07:24:43 GMT (envelope-from avg@svn.freebsd.org) Message-Id: <201009060724.o867OhJ5021820@svn.freebsd.org> From: Andriy Gapon Date: Mon, 6 Sep 2010 07:24:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212250 - stable/8/sys/dev/acpica X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Sep 2010 07:24:44 -0000 Author: avg Date: Mon Sep 6 07:24:43 2010 New Revision: 212250 URL: http://svn.freebsd.org/changeset/base/212250 Log: MFC r212172: acpi: update stale comments about order of cpu devices probing Modified: stable/8/sys/dev/acpica/acpi.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/dev/acpica/acpi.c ============================================================================== --- stable/8/sys/dev/acpica/acpi.c Mon Sep 6 07:24:28 2010 (r212249) +++ stable/8/sys/dev/acpica/acpi.c Mon Sep 6 07:24:43 2010 (r212250) @@ -1699,10 +1699,10 @@ acpi_probe_order(ACPI_HANDLE handle, int ACPI_OBJECT_TYPE type; /* - * 1. I/O port and memory system resource holders - * 2. Embedded controllers (to handle early accesses) - * 3. PCI Link Devices - * 100000. CPUs + * 1. CPUs + * 2. I/O port and memory system resource holders + * 3. Embedded controllers (to handle early accesses) + * 4. PCI Link Devices */ AcpiGetType(handle, &type); if (type == ACPI_TYPE_PROCESSOR) @@ -1762,8 +1762,7 @@ acpi_probe_child(ACPI_HANDLE handle, UIN * placeholder so that the probe/attach passes will run * breadth-first. Orders less than ACPI_DEV_BASE_ORDER * are reserved for special objects (i.e., system - * resources). CPU devices have a very high order to - * ensure they are probed after other devices. + * resources). */ ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "scanning '%s'\n", handle_str)); order = level * 10 + 100; From owner-svn-src-stable@FreeBSD.ORG Mon Sep 6 15:48:06 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E57F51065694; Mon, 6 Sep 2010 15:48:06 +0000 (UTC) (envelope-from jh@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D42FE8FC0A; Mon, 6 Sep 2010 15:48:06 +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 o86Fm6qx054951; Mon, 6 Sep 2010 15:48:06 GMT (envelope-from jh@svn.freebsd.org) Received: (from jh@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o86Fm6QM054949; Mon, 6 Sep 2010 15:48:06 GMT (envelope-from jh@svn.freebsd.org) Message-Id: <201009061548.o86Fm6QM054949@svn.freebsd.org> From: Jaakko Heinonen Date: Mon, 6 Sep 2010 15:48:06 +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: r212258 - stable/7/sbin/bsdlabel X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Sep 2010 15:48:07 -0000 Author: jh Date: Mon Sep 6 15:48:06 2010 New Revision: 212258 URL: http://svn.freebsd.org/changeset/base/212258 Log: MFC r211342: - Check that strtoul(3) succeeds to convert the entire string in a few places. - In getasciilabel(), set the disk type only when a valid type is given. PR: bin/86765 Modified: stable/7/sbin/bsdlabel/bsdlabel.c Directory Properties: stable/7/sbin/bsdlabel/ (props changed) Modified: stable/7/sbin/bsdlabel/bsdlabel.c ============================================================================== --- stable/7/sbin/bsdlabel/bsdlabel.c Mon Sep 6 13:47:11 2010 (r212257) +++ stable/7/sbin/bsdlabel/bsdlabel.c Mon Sep 6 15:48:06 2010 (r212258) @@ -727,7 +727,7 @@ word(char *cp) static int getasciilabel(FILE *f, struct disklabel *lp) { - char *cp; + char *cp, *endp; const char **cpp; u_int part; char *tp, line[BUFSIZ]; @@ -766,11 +766,15 @@ getasciilabel(FILE *f, struct disklabel } if (cpp < &dktypenames[DKMAXTYPES]) continue; - v = strtoul(tp, NULL, 10); + errno = 0; + v = strtoul(tp, &endp, 10); + if (errno != 0 || *endp != '\0') + v = DKMAXTYPES; if (v >= DKMAXTYPES) fprintf(stderr, "line %d:%s %lu\n", lineno, "Warning, unknown disk type", v); - lp->d_type = v; + else + lp->d_type = v; continue; } if (!strcmp(cp, "flags")) { @@ -995,7 +999,7 @@ static int getasciipartspec(char *tp, struct disklabel *lp, int part, int lineno) { struct partition *pp; - char *cp; + char *cp, *endp; const char **cpp; u_long v; @@ -1031,9 +1035,12 @@ getasciipartspec(char *tp, struct diskla if (*cpp != NULL) { pp->p_fstype = cpp - fstypenames; } else { - if (isdigit(*cp)) - v = strtoul(cp, NULL, 10); - else + if (isdigit(*cp)) { + errno = 0; + v = strtoul(cp, &endp, 10); + if (errno != 0 || *endp != '\0') + v = FSMAXTYPES; + } else v = FSMAXTYPES; if (v >= FSMAXTYPES) { fprintf(stderr, From owner-svn-src-stable@FreeBSD.ORG Mon Sep 6 22:28:47 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 984DF10656E7; Mon, 6 Sep 2010 22:28:47 +0000 (UTC) (envelope-from weongyo@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 40B828FC17; Mon, 6 Sep 2010 22:28:47 +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 o86MSlQF068319; Mon, 6 Sep 2010 22:28:47 GMT (envelope-from weongyo@svn.freebsd.org) Received: (from weongyo@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o86MSl3T068317; Mon, 6 Sep 2010 22:28:47 GMT (envelope-from weongyo@svn.freebsd.org) Message-Id: <201009062228.o86MSl3T068317@svn.freebsd.org> From: Weongyo Jeong Date: Mon, 6 Sep 2010 22:28:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212273 - stable/8/sys/dev/bwn X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Sep 2010 22:28:47 -0000 Author: weongyo Date: Mon Sep 6 22:28:46 2010 New Revision: 212273 URL: http://svn.freebsd.org/changeset/base/212273 Log: MFC r210393: Fixes a mistake to calculate CALC_COEFF2() value that tmp[3] is used even if it's unreachable. PR: kern/144505 Submitted by: Henning Petersen Modified: stable/8/sys/dev/bwn/if_bwn.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/dev/bwn/if_bwn.c ============================================================================== --- stable/8/sys/dev/bwn/if_bwn.c Mon Sep 6 22:23:35 2010 (r212272) +++ stable/8/sys/dev/bwn/if_bwn.c Mon Sep 6 22:28:46 2010 (r212273) @@ -12828,9 +12828,9 @@ bwn_phy_lp_calc_rx_iq_comp(struct bwn_ma int _t; \ _t = _x - 11; \ if (_t >= 0) \ - tmp[3] = (_y << (31 - _x)) / (_z >> _t); \ + _v = (_y << (31 - _x)) / (_z >> _t); \ else \ - tmp[3] = (_y << (31 - _x)) / (_z << -_t); \ + _v = (_y << (31 - _x)) / (_z << -_t); \ } while (0) struct bwn_phy_lp_iq_est ie; uint16_t v0, v1; From owner-svn-src-stable@FreeBSD.ORG Mon Sep 6 22:31:24 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E5D0C1065674; Mon, 6 Sep 2010 22:31:24 +0000 (UTC) (envelope-from weongyo@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D49538FC0A; Mon, 6 Sep 2010 22:31:24 +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 o86MVOpH068462; Mon, 6 Sep 2010 22:31:24 GMT (envelope-from weongyo@svn.freebsd.org) Received: (from weongyo@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o86MVOKH068460; Mon, 6 Sep 2010 22:31:24 GMT (envelope-from weongyo@svn.freebsd.org) Message-Id: <201009062231.o86MVOKH068460@svn.freebsd.org> From: Weongyo Jeong Date: Mon, 6 Sep 2010 22:31:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212274 - stable/8/sys/dev/bwn X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Sep 2010 22:31:25 -0000 Author: weongyo Date: Mon Sep 6 22:31:24 2010 New Revision: 212274 URL: http://svn.freebsd.org/changeset/base/212274 Log: MFC r209888: Fixes a bug for LP PHY that some frames have 2 padding bytes at the start so we should adjust the mbuf if the driver is running in PIO mode. Now it should work well with WPA authentication and association for LP PHY devices. Tested by: Warren Block Modified: stable/8/sys/dev/bwn/if_bwn.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/dev/bwn/if_bwn.c ============================================================================== --- stable/8/sys/dev/bwn/if_bwn.c Mon Sep 6 22:28:46 2010 (r212273) +++ stable/8/sys/dev/bwn/if_bwn.c Mon Sep 6 22:31:24 2010 (r212274) @@ -9073,7 +9073,7 @@ bwn_pio_rxeof(struct bwn_pio_rxqueue *pr struct mbuf *m; uint32_t ctl32, macstat, v32; unsigned int i, padding; - uint16_t ctl16, len, v16; + uint16_t ctl16, len, totlen, v16; unsigned char *mp; char *data; @@ -9132,7 +9132,8 @@ ready: } padding = (macstat & BWN_RX_MAC_PADDING) ? 2 : 0; - KASSERT(len + padding <= MCLBYTES, ("too big..\n")); + totlen = len + padding; + KASSERT(totlen <= MCLBYTES, ("too big..\n")); m = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR); if (m == NULL) { device_printf(sc->sc_dev, "%s: out of memory", __func__); @@ -9140,12 +9141,12 @@ ready: } mp = mtod(m, unsigned char *); if (prq->prq_rev >= 8) { - siba_read_multi_4(sc->sc_dev, mp + padding, (len & ~3), + siba_read_multi_4(sc->sc_dev, mp, (totlen & ~3), prq->prq_base + BWN_PIO8_RXDATA); - if (len & 3) { + if (totlen & 3) { v32 = bwn_pio_rx_read_4(prq, BWN_PIO8_RXDATA); - data = &(mp[len + padding - 1]); - switch (len & 3) { + data = &(mp[totlen - 1]); + switch (totlen & 3) { case 3: *data = (v32 >> 16); data--; @@ -9157,16 +9158,16 @@ ready: } } } else { - siba_read_multi_2(sc->sc_dev, mp + padding, (len & ~1), + siba_read_multi_2(sc->sc_dev, mp, (totlen & ~1), prq->prq_base + BWN_PIO_RXDATA); - if (len & 1) { + if (totlen & 1) { v16 = bwn_pio_rx_read_2(prq, BWN_PIO_RXDATA); - mp[len + padding - 1] = v16; + mp[totlen - 1] = v16; } } m->m_pkthdr.rcvif = ifp; - m->m_len = m->m_pkthdr.len = len + padding; + m->m_len = m->m_pkthdr.len = totlen; bwn_rxeof(prq->prq_mac, m, &rxhdr); From owner-svn-src-stable@FreeBSD.ORG Mon Sep 6 22:47:53 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4F56F10656A4; Mon, 6 Sep 2010 22:47:53 +0000 (UTC) (envelope-from weongyo@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 23B258FC1C; Mon, 6 Sep 2010 22:47:53 +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 o86MlrXG068969; Mon, 6 Sep 2010 22:47:53 GMT (envelope-from weongyo@svn.freebsd.org) Received: (from weongyo@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o86MlrZA068966; Mon, 6 Sep 2010 22:47:53 GMT (envelope-from weongyo@svn.freebsd.org) Message-Id: <201009062247.o86MlrZA068966@svn.freebsd.org> From: Weongyo Jeong Date: Mon, 6 Sep 2010 22:47:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212275 - in stable/8/sys: conf modules X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Sep 2010 22:47:53 -0000 Author: weongyo Date: Mon Sep 6 22:47:52 2010 New Revision: 212275 URL: http://svn.freebsd.org/changeset/base/212275 Log: MFC r196636: Connect bwi up to the build. While there are some problems with this driver still, it generally works well for most people most of the time. It is still too green for GENERIC, however. Submitted by: many (latest being kwm@) Approved by: imp Requested by: Warren Block Modified: stable/8/sys/conf/NOTES stable/8/sys/modules/Makefile Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/conf/NOTES ============================================================================== --- stable/8/sys/conf/NOTES Mon Sep 6 22:31:24 2010 (r212274) +++ stable/8/sys/conf/NOTES Mon Sep 6 22:47:52 2010 (r212275) @@ -1845,6 +1845,7 @@ device miibus # BCM570x family of controllers, including the 3Com 3c996-T, # the Netgear GA302T, the SysKonnect SK-9D21 and SK-9D41, and # the embedded gigE NICs on Dell PowerEdge 2550 servers. +# bwi: Broadcom BCM430* and BCM431* family of wireless adapters. # cas: Sun Cassini/Cassini+ and National Semiconductor DP83065 Saturn # cm: Arcnet SMC COM90c26 / SMC COM90c56 # (and SMC COM90c66 in '56 compatibility mode) adapters. @@ -2016,6 +2017,7 @@ device wb # Winbond W89C840F device xl # 3Com 3c90x (``Boomerang'', ``Cyclone'') # PCI Ethernet NICs. +device bwi # Broadcom BCM430* BCM431* device de # DEC/Intel DC21x4x (``Tulip'') device em # Intel Pro/1000 Gigabit Ethernet device igb # Intel Pro/1000 PCIE Gigabit Ethernet Modified: stable/8/sys/modules/Makefile ============================================================================== --- stable/8/sys/modules/Makefile Mon Sep 6 22:31:24 2010 (r212274) +++ stable/8/sys/modules/Makefile Mon Sep 6 22:47:52 2010 (r212275) @@ -42,6 +42,7 @@ SUBDIR= ${_3dfx} \ ${_bktr} \ ${_bm} \ bridgestp \ + bwi \ bwn \ cam \ ${_canbepm} \ From owner-svn-src-stable@FreeBSD.ORG Tue Sep 7 11:46:09 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C1D8D10656B4; Tue, 7 Sep 2010 11:46:09 +0000 (UTC) (envelope-from bz@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id B0D8C8FC20; Tue, 7 Sep 2010 11:46:09 +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 o87Bk9nM096323; Tue, 7 Sep 2010 11:46:09 GMT (envelope-from bz@svn.freebsd.org) Received: (from bz@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o87Bk9w0096321; Tue, 7 Sep 2010 11:46:09 GMT (envelope-from bz@svn.freebsd.org) Message-Id: <201009071146.o87Bk9w0096321@svn.freebsd.org> From: "Bjoern A. Zeeb" Date: Tue, 7 Sep 2010 11:46:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212287 - stable/8/sys/net X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Sep 2010 11:46:09 -0000 Author: bz Date: Tue Sep 7 11:46:09 2010 New Revision: 212287 URL: http://svn.freebsd.org/changeset/base/212287 Log: MFC r212152: MFp4 CH=183259: No reason to use if_free_type() as we don't change our type. Just if_free() is fine. Modified: stable/8/sys/net/if_epair.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/net/if_epair.c ============================================================================== --- stable/8/sys/net/if_epair.c Tue Sep 7 08:33:17 2010 (r212286) +++ stable/8/sys/net/if_epair.c Tue Sep 7 11:46:09 2010 (r212287) @@ -901,9 +901,9 @@ epair_clone_destroy(struct if_clone *ifc * we need to switch before freeing them. */ CURVNET_SET_QUIET(oifp->if_vnet); - if_free_type(oifp, IFT_ETHER); + if_free(oifp); CURVNET_RESTORE(); - if_free_type(ifp, IFT_ETHER); + if_free(ifp); free(scb, M_EPAIR); free(sca, M_EPAIR); ifc_free_unit(ifc, unit); From owner-svn-src-stable@FreeBSD.ORG Tue Sep 7 12:02:35 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 845AB10656B4; Tue, 7 Sep 2010 12:02:34 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 9BA3F8FC1F; Tue, 7 Sep 2010 12:02:34 +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 o87C2YqD096989; Tue, 7 Sep 2010 12:02:34 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o87C2Ynq096987; Tue, 7 Sep 2010 12:02:34 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201009071202.o87C2Ynq096987@svn.freebsd.org> From: Konstantin Belousov Date: Tue, 7 Sep 2010 12:02:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212288 - stable/8/lib/libthr/thread X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Sep 2010 12:02:36 -0000 Author: kib Date: Tue Sep 7 12:02:34 2010 New Revision: 212288 URL: http://svn.freebsd.org/changeset/base/212288 Log: MFC r211742: The __hidden definition is provided by sys/cdefs.h. Modified: stable/8/lib/libthr/thread/thr_private.h Directory Properties: stable/8/lib/libthr/ (props changed) Modified: stable/8/lib/libthr/thread/thr_private.h ============================================================================== --- stable/8/lib/libthr/thread/thr_private.h Tue Sep 7 11:46:09 2010 (r212287) +++ stable/8/lib/libthr/thread/thr_private.h Tue Sep 7 12:02:34 2010 (r212288) @@ -52,10 +52,6 @@ #include #include -#ifndef __hidden -#define __hidden __attribute__((visibility("hidden"))) -#endif - #include "pthread_md.h" #include "thr_umtx.h" #include "thread_db.h" From owner-svn-src-stable@FreeBSD.ORG Tue Sep 7 12:04:08 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1B0F91065698; Tue, 7 Sep 2010 12:04:08 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id E3C748FC08; Tue, 7 Sep 2010 12:04: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 o87C47E2097085; Tue, 7 Sep 2010 12:04:07 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o87C47Du097084; Tue, 7 Sep 2010 12:04:07 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201009071204.o87C47Du097084@svn.freebsd.org> From: Konstantin Belousov Date: Tue, 7 Sep 2010 12:04:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212289 - stable/8/lib/libthr/thread X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Sep 2010 12:04:08 -0000 Author: kib Date: Tue Sep 7 12:04:07 2010 New Revision: 212289 URL: http://svn.freebsd.org/changeset/base/212289 Log: MFC r211743: Remove unused source. Deleted: stable/8/lib/libthr/thread/thr_atfork.c Modified: Directory Properties: stable/8/lib/libthr/ (props changed) From owner-svn-src-stable@FreeBSD.ORG Tue Sep 7 12:06:42 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 014F01065694; Tue, 7 Sep 2010 12:06:42 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id C9DB28FC18; Tue, 7 Sep 2010 12:06:41 +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 o87C6fGE097197; Tue, 7 Sep 2010 12:06:41 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o87C6fBP097193; Tue, 7 Sep 2010 12:06:41 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201009071206.o87C6fBP097193@svn.freebsd.org> From: Konstantin Belousov Date: Tue, 7 Sep 2010 12:06:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212290 - stable/8/lib/libc/sys X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Sep 2010 12:06:42 -0000 Author: kib Date: Tue Sep 7 12:06:41 2010 New Revision: 212290 URL: http://svn.freebsd.org/changeset/base/212290 Log: MFC r211748: Move the __stack_chk_fail_local@FBSD_1.0 compat symbol definition into the separate .o for libc_pic.a. This prevents rtld from making the symbol global. Added: stable/8/lib/libc/sys/stack_protector_compat.c - copied unchanged from r211748, head/lib/libc/sys/stack_protector_compat.c Modified: stable/8/lib/libc/sys/Makefile.inc stable/8/lib/libc/sys/stack_protector.c Directory Properties: stable/8/lib/libc/ (props changed) stable/8/lib/libc/locale/ (props changed) stable/8/lib/libc/stdtime/ (props changed) stable/8/lib/libc/sys/ (props changed) Modified: stable/8/lib/libc/sys/Makefile.inc ============================================================================== --- stable/8/lib/libc/sys/Makefile.inc Tue Sep 7 12:04:07 2010 (r212289) +++ stable/8/lib/libc/sys/Makefile.inc Tue Sep 7 12:06:41 2010 (r212290) @@ -18,7 +18,7 @@ .endif # Sources common to both syscall interfaces: -SRCS+= stack_protector.c __error.c +SRCS+= stack_protector.c stack_protector_compat.c __error.c .if !defined(WITHOUT_SYSCALL_COMPAT) SRCS+= fcntl.c ftruncate.c lseek.c mmap.c pread.c pwrite.c truncate.c PSEUDO+= _fcntl.o Modified: stable/8/lib/libc/sys/stack_protector.c ============================================================================== --- stable/8/lib/libc/sys/stack_protector.c Tue Sep 7 12:04:07 2010 (r212289) +++ stable/8/lib/libc/sys/stack_protector.c Tue Sep 7 12:06:41 2010 (r212290) @@ -107,8 +107,6 @@ __chk_fail(void) __fail("buffer overflow detected; terminated"); } -#ifdef PIC -__sym_compat(__stack_chk_fail_local, __stack_chk_fail, FBSD_1.0); -#else +#ifndef PIC __weak_reference(__stack_chk_fail, __stack_chk_fail_local); #endif Copied: stable/8/lib/libc/sys/stack_protector_compat.c (from r211748, head/lib/libc/sys/stack_protector_compat.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/8/lib/libc/sys/stack_protector_compat.c Tue Sep 7 12:06:41 2010 (r212290, copy of r211748, head/lib/libc/sys/stack_protector_compat.c) @@ -0,0 +1,20 @@ +/* + * Written by Alexander Kabaev + * The file is in public domain. + */ + +#include +__FBSDID("$FreeBSD$"); + +void __stack_chk_fail(void); + +#ifdef PIC +void +__stack_chk_fail_local_hidden(void) +{ + + __stack_chk_fail(); +} + +__sym_compat(__stack_chk_fail_local, __stack_chk_fail_local_hidden, FBSD_1.0); +#endif From owner-svn-src-stable@FreeBSD.ORG Tue Sep 7 13:10:46 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C6FFD1065695; Tue, 7 Sep 2010 13:10:46 +0000 (UTC) (envelope-from bz@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id B5F678FC08; Tue, 7 Sep 2010 13:10:46 +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 o87DAkEJ099621; Tue, 7 Sep 2010 13:10:46 GMT (envelope-from bz@svn.freebsd.org) Received: (from bz@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o87DAk66099619; Tue, 7 Sep 2010 13:10:46 GMT (envelope-from bz@svn.freebsd.org) Message-Id: <201009071310.o87DAk66099619@svn.freebsd.org> From: "Bjoern A. Zeeb" Date: Tue, 7 Sep 2010 13:10:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212291 - stable/8/sys/netinet X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Sep 2010 13:10:46 -0000 Author: bz Date: Tue Sep 7 13:10:46 2010 New Revision: 212291 URL: http://svn.freebsd.org/changeset/base/212291 Log: MFC r212209: In case of RADIX_MPATH do not leak the IN_IFADDR read lock on early return. Modified: stable/8/sys/netinet/in.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/netinet/in.c ============================================================================== --- stable/8/sys/netinet/in.c Tue Sep 7 12:06:41 2010 (r212290) +++ stable/8/sys/netinet/in.c Tue Sep 7 13:10:46 2010 (r212291) @@ -1042,9 +1042,10 @@ in_addprefix(struct in_ifaddr *target, i if (ia->ia_flags & IFA_ROUTE) { #ifdef RADIX_MPATH if (ia->ia_addr.sin_addr.s_addr == - target->ia_addr.sin_addr.s_addr) + target->ia_addr.sin_addr.s_addr) { + IN_IFADDR_RUNLOCK(); return (EEXIST); - else + } else break; #endif if (V_sameprefixcarponly && From owner-svn-src-stable@FreeBSD.ORG Tue Sep 7 18:14:51 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 291AF1065672; Tue, 7 Sep 2010 18:14:51 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 16D6E8FC1C; Tue, 7 Sep 2010 18:14:51 +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 o87IEoY4014273; Tue, 7 Sep 2010 18:14:50 GMT (envelope-from delphij@svn.freebsd.org) Received: (from delphij@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o87IEolf014267; Tue, 7 Sep 2010 18:14:50 GMT (envelope-from delphij@svn.freebsd.org) Message-Id: <201009071814.o87IEolf014267@svn.freebsd.org> From: Xin LI Date: Tue, 7 Sep 2010 18:14:50 +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: r212300 - in stable/7/sys/boot/i386: boot2 gptboot loader zfsboot zfsloader X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Sep 2010 18:14:51 -0000 Author: delphij Date: Tue Sep 7 18:14:50 2010 New Revision: 212300 URL: http://svn.freebsd.org/changeset/base/212300 Log: MFC r205662 + r212066 (except efi part): Our boot loader is capable of booting both i386 and amd64 kernels so call it "x86" instead of "i386". Modified: stable/7/sys/boot/i386/boot2/boot2.c stable/7/sys/boot/i386/gptboot/gptboot.c stable/7/sys/boot/i386/loader/Makefile stable/7/sys/boot/i386/zfsboot/zfsboot.c stable/7/sys/boot/i386/zfsloader/Makefile 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/boot/i386/boot2/boot2.c ============================================================================== --- stable/7/sys/boot/i386/boot2/boot2.c Tue Sep 7 17:56:29 2010 (r212299) +++ stable/7/sys/boot/i386/boot2/boot2.c Tue Sep 7 18:14:50 2010 (r212300) @@ -283,7 +283,7 @@ main(void) for (;;) { if (!autoboot || !OPT_CHECK(RBX_QUIET)) - printf("\nFreeBSD/i386 boot\n" + printf("\nFreeBSD/x86 boot\n" "Default: %u:%s(%u,%c)%s\n" "boot: ", dsk.drive & DRV_MASK, dev_nm[dsk.type], dsk.unit, Modified: stable/7/sys/boot/i386/gptboot/gptboot.c ============================================================================== --- stable/7/sys/boot/i386/gptboot/gptboot.c Tue Sep 7 17:56:29 2010 (r212299) +++ stable/7/sys/boot/i386/gptboot/gptboot.c Tue Sep 7 18:14:50 2010 (r212300) @@ -281,7 +281,7 @@ main(void) for (;;) { if (!autoboot || !OPT_CHECK(RBX_QUIET)) - printf("\nFreeBSD/i386 boot\n" + printf("\nFreeBSD/x86 boot\n" "Default: %u:%s(%up%u)%s\n" "boot: ", dsk.drive & DRV_MASK, dev_nm[dsk.type], dsk.unit, Modified: stable/7/sys/boot/i386/loader/Makefile ============================================================================== --- stable/7/sys/boot/i386/loader/Makefile Tue Sep 7 17:56:29 2010 (r212299) +++ stable/7/sys/boot/i386/loader/Makefile Tue Sep 7 18:14:50 2010 (r212300) @@ -5,7 +5,7 @@ LOADER?= loader PROG= ${LOADER}.sym INTERNALPROG= -NEWVERSWHAT?= "bootstrap loader" i386 +NEWVERSWHAT?= "bootstrap loader" x86 # architecture-specific loader code SRCS= main.c conf.c vers.c Modified: stable/7/sys/boot/i386/zfsboot/zfsboot.c ============================================================================== --- stable/7/sys/boot/i386/zfsboot/zfsboot.c Tue Sep 7 17:56:29 2010 (r212299) +++ stable/7/sys/boot/i386/zfsboot/zfsboot.c Tue Sep 7 18:14:50 2010 (r212300) @@ -731,7 +731,7 @@ main(void) for (;;) { if (!autoboot || !OPT_CHECK(RBX_QUIET)) - printf("\nFreeBSD/i386 boot\n" + printf("\nFreeBSD/x86 boot\n" "Default: %s:%s\n" "boot: ", spa->spa_name, kname); Modified: stable/7/sys/boot/i386/zfsloader/Makefile ============================================================================== --- stable/7/sys/boot/i386/zfsloader/Makefile Tue Sep 7 17:56:29 2010 (r212299) +++ stable/7/sys/boot/i386/zfsloader/Makefile Tue Sep 7 18:14:50 2010 (r212300) @@ -3,7 +3,7 @@ .PATH: ${.CURDIR}/../loader LOADER= zfsloader -NEWVERSWHAT= "ZFS enabled bootstrap loader" i386 +NEWVERSWHAT= "ZFS enabled bootstrap loader" x86 LOADER_ZFS_SUPPORT=yes LOADER_ONLY= yes NO_MAN= yes From owner-svn-src-stable@FreeBSD.ORG Tue Sep 7 18:14:59 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 92D251065811; Tue, 7 Sep 2010 18:14:59 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 80D5E8FC26; Tue, 7 Sep 2010 18:14:59 +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 o87IExmI014328; Tue, 7 Sep 2010 18:14:59 GMT (envelope-from delphij@svn.freebsd.org) Received: (from delphij@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o87IEx4h014322; Tue, 7 Sep 2010 18:14:59 GMT (envelope-from delphij@svn.freebsd.org) Message-Id: <201009071814.o87IEx4h014322@svn.freebsd.org> From: Xin LI Date: Tue, 7 Sep 2010 18:14:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212301 - in stable/8/sys/boot/i386: boot2 gptboot loader zfsboot zfsloader X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Sep 2010 18:14:59 -0000 Author: delphij Date: Tue Sep 7 18:14:59 2010 New Revision: 212301 URL: http://svn.freebsd.org/changeset/base/212301 Log: MFC r205662 + r212066 (except efi part): Our boot loader is capable of booting both i386 and amd64 kernels so call it "x86" instead of "i386". Modified: stable/8/sys/boot/i386/boot2/boot2.c stable/8/sys/boot/i386/gptboot/gptboot.c stable/8/sys/boot/i386/loader/Makefile stable/8/sys/boot/i386/zfsboot/zfsboot.c stable/8/sys/boot/i386/zfsloader/Makefile Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/boot/i386/boot2/boot2.c ============================================================================== --- stable/8/sys/boot/i386/boot2/boot2.c Tue Sep 7 18:14:50 2010 (r212300) +++ stable/8/sys/boot/i386/boot2/boot2.c Tue Sep 7 18:14:59 2010 (r212301) @@ -283,7 +283,7 @@ main(void) for (;;) { if (!autoboot || !OPT_CHECK(RBX_QUIET)) - printf("\nFreeBSD/i386 boot\n" + printf("\nFreeBSD/x86 boot\n" "Default: %u:%s(%u,%c)%s\n" "boot: ", dsk.drive & DRV_MASK, dev_nm[dsk.type], dsk.unit, Modified: stable/8/sys/boot/i386/gptboot/gptboot.c ============================================================================== --- stable/8/sys/boot/i386/gptboot/gptboot.c Tue Sep 7 18:14:50 2010 (r212300) +++ stable/8/sys/boot/i386/gptboot/gptboot.c Tue Sep 7 18:14:59 2010 (r212301) @@ -281,7 +281,7 @@ main(void) for (;;) { if (!autoboot || !OPT_CHECK(RBX_QUIET)) - printf("\nFreeBSD/i386 boot\n" + printf("\nFreeBSD/x86 boot\n" "Default: %u:%s(%up%u)%s\n" "boot: ", dsk.drive & DRV_MASK, dev_nm[dsk.type], dsk.unit, Modified: stable/8/sys/boot/i386/loader/Makefile ============================================================================== --- stable/8/sys/boot/i386/loader/Makefile Tue Sep 7 18:14:50 2010 (r212300) +++ stable/8/sys/boot/i386/loader/Makefile Tue Sep 7 18:14:59 2010 (r212301) @@ -6,7 +6,7 @@ MK_SSP= no LOADER?= loader PROG= ${LOADER}.sym INTERNALPROG= -NEWVERSWHAT?= "bootstrap loader" i386 +NEWVERSWHAT?= "bootstrap loader" x86 # architecture-specific loader code SRCS= main.c conf.c vers.c Modified: stable/8/sys/boot/i386/zfsboot/zfsboot.c ============================================================================== --- stable/8/sys/boot/i386/zfsboot/zfsboot.c Tue Sep 7 18:14:50 2010 (r212300) +++ stable/8/sys/boot/i386/zfsboot/zfsboot.c Tue Sep 7 18:14:59 2010 (r212301) @@ -731,7 +731,7 @@ main(void) for (;;) { if (!autoboot || !OPT_CHECK(RBX_QUIET)) - printf("\nFreeBSD/i386 boot\n" + printf("\nFreeBSD/x86 boot\n" "Default: %s:%s\n" "boot: ", spa->spa_name, kname); Modified: stable/8/sys/boot/i386/zfsloader/Makefile ============================================================================== --- stable/8/sys/boot/i386/zfsloader/Makefile Tue Sep 7 18:14:50 2010 (r212300) +++ stable/8/sys/boot/i386/zfsloader/Makefile Tue Sep 7 18:14:59 2010 (r212301) @@ -3,7 +3,7 @@ .PATH: ${.CURDIR}/../loader LOADER= zfsloader -NEWVERSWHAT= "ZFS enabled bootstrap loader" i386 +NEWVERSWHAT= "ZFS enabled bootstrap loader" x86 LOADER_ZFS_SUPPORT=yes LOADER_ONLY= yes NO_MAN= yes From owner-svn-src-stable@FreeBSD.ORG Wed Sep 8 01:18:09 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EA8A210656B8; Wed, 8 Sep 2010 01:18:09 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D915E8FC17; Wed, 8 Sep 2010 01:18:09 +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 o881I9XS056427; Wed, 8 Sep 2010 01:18:09 GMT (envelope-from rmacklem@svn.freebsd.org) Received: (from rmacklem@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o881I9GV056425; Wed, 8 Sep 2010 01:18:09 GMT (envelope-from rmacklem@svn.freebsd.org) Message-Id: <201009080118.o881I9GV056425@svn.freebsd.org> From: Rick Macklem Date: Wed, 8 Sep 2010 01:18:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212309 - stable/8/sys/rpc X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Sep 2010 01:18:10 -0000 Author: rmacklem Date: Wed Sep 8 01:18:09 2010 New Revision: 212309 URL: http://svn.freebsd.org/changeset/base/212309 Log: MFC: r211789 If the first iteration of the do loop in replay_prune() succeeded and a subsequent interation failed to find an entry to prune, it could loop infinitely, since the "freed" variable wasn't reset to FALSE. This patch moves setting freed FALSE to inside the loop to fix the problem. Modified: stable/8/sys/rpc/replay.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/rpc/replay.c ============================================================================== --- stable/8/sys/rpc/replay.c Tue Sep 7 23:31:48 2010 (r212308) +++ stable/8/sys/rpc/replay.c Wed Sep 8 01:18:09 2010 (r212309) @@ -144,8 +144,8 @@ replay_prune(struct replay_cache *rc) bool_t freed_one; if (rc->rc_count >= REPLAY_MAX || rc->rc_size > rc->rc_maxsize) { - freed_one = FALSE; do { + freed_one = FALSE; /* * Try to free an entry. Don't free in-progress entries */ From owner-svn-src-stable@FreeBSD.ORG Wed Sep 8 01:41:23 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7191810656B1; Wed, 8 Sep 2010 01:41:23 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 601A38FC13; Wed, 8 Sep 2010 01:41:23 +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 o881fNAh059034; Wed, 8 Sep 2010 01:41:23 GMT (envelope-from rmacklem@svn.freebsd.org) Received: (from rmacklem@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o881fMXS059032; Wed, 8 Sep 2010 01:41:22 GMT (envelope-from rmacklem@svn.freebsd.org) Message-Id: <201009080141.o881fMXS059032@svn.freebsd.org> From: Rick Macklem Date: Wed, 8 Sep 2010 01:41:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212310 - stable/8/sys/rpc X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Sep 2010 01:41:23 -0000 Author: rmacklem Date: Wed Sep 8 01:41:22 2010 New Revision: 212310 URL: http://svn.freebsd.org/changeset/base/212310 Log: MFC: r211830 Add mutex locking for the call to replay_prune() in replay_setsize(), since replay_prune() expects the rc_lock to be held when it is called. Modified: stable/8/sys/rpc/replay.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/rpc/replay.c ============================================================================== --- stable/8/sys/rpc/replay.c Wed Sep 8 01:18:09 2010 (r212309) +++ stable/8/sys/rpc/replay.c Wed Sep 8 01:41:22 2010 (r212310) @@ -90,8 +90,10 @@ void replay_setsize(struct replay_cache *rc, size_t newmaxsize) { + mtx_lock(&rc->rc_lock); rc->rc_maxsize = newmaxsize; replay_prune(rc); + mtx_unlock(&rc->rc_lock); } void From owner-svn-src-stable@FreeBSD.ORG Wed Sep 8 01:55:03 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A26BA10656C8; Wed, 8 Sep 2010 01:55:03 +0000 (UTC) (envelope-from davidxu@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 76B7D8FC16; Wed, 8 Sep 2010 01:55:03 +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 o881t3SF060497; Wed, 8 Sep 2010 01:55:03 GMT (envelope-from davidxu@svn.freebsd.org) Received: (from davidxu@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o881t3oG060495; Wed, 8 Sep 2010 01:55:03 GMT (envelope-from davidxu@svn.freebsd.org) Message-Id: <201009080155.o881t3oG060495@svn.freebsd.org> From: David Xu Date: Wed, 8 Sep 2010 01:55:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212311 - stable/8/sys/kern X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Sep 2010 01:55:03 -0000 Author: davidxu Date: Wed Sep 8 01:55:03 2010 New Revision: 212311 URL: http://svn.freebsd.org/changeset/base/212311 Log: MFC: r212047 If a process is being debugged, skips job control caused by SIGSTOP/SIGCONT signals, because it is managed by debugger, however a normal signal sent to a interruptibly sleeping thread wakes up the thread so it will handle the signal when the process leaves the stopped state. Modified: stable/8/sys/kern/kern_sig.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/kern/kern_sig.c ============================================================================== --- stable/8/sys/kern/kern_sig.c Wed Sep 8 01:41:22 2010 (r212310) +++ stable/8/sys/kern/kern_sig.c Wed Sep 8 01:55:03 2010 (r212311) @@ -2129,20 +2129,13 @@ tdsignal(struct proc *p, struct thread * * We try do the per-process part here. */ if (P_SHOULDSTOP(p)) { - /* - * The process is in stopped mode. All the threads should be - * either winding down or already on the suspended queue. - */ - if (p->p_flag & P_TRACED) { + if (sig == SIGKILL) { /* - * The traced process is already stopped, - * so no further action is necessary. - * No signal can restart us. + * If traced process is already stopped, + * then no further action is necessary. */ - goto out; - } - - if (sig == SIGKILL) { + if (p->p_flag & P_TRACED) + goto out; /* * SIGKILL sets process running. * It will die elsewhere. @@ -2154,6 +2147,12 @@ tdsignal(struct proc *p, struct thread * if (prop & SA_CONT) { /* + * If traced process is already stopped, + * then no further action is necessary. + */ + if (p->p_flag & P_TRACED) + goto out; + /* * If SIGCONT is default (or ignored), we continue the * process but don't leave the signal in sigqueue as * it has no further action. If SIGCONT is held, we @@ -2198,6 +2197,12 @@ tdsignal(struct proc *p, struct thread * if (prop & SA_STOP) { /* + * If traced process is already stopped, + * then no further action is necessary. + */ + if (p->p_flag & P_TRACED) + goto out; + /* * Already stopped, don't need to stop again * (If we did the shell could get confused). * Just make sure the signal STOP bit set. From owner-svn-src-stable@FreeBSD.ORG Wed Sep 8 08:03:08 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D0B5F10656C3; Wed, 8 Sep 2010 08:03:08 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id BF8B58FC1E; Wed, 8 Sep 2010 08:03:08 +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 o88838gY093668; Wed, 8 Sep 2010 08:03:08 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o888385g093666; Wed, 8 Sep 2010 08:03:08 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <201009080803.o888385g093666@svn.freebsd.org> From: Ed Schouten Date: Wed, 8 Sep 2010 08:03:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212314 - stable/8/share/man/man4 X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Sep 2010 08:03:09 -0000 Author: ed Date: Wed Sep 8 08:03:08 2010 New Revision: 212314 URL: http://svn.freebsd.org/changeset/base/212314 Log: MFC r212087: Remove reference to device minor numbers in psm(4) man page. The number returned by stat(2) is generated automatically, so it is not possible to deduce whether the device is blocking or not. Modified: stable/8/share/man/man4/psm.4 Directory Properties: stable/8/share/man/man4/ (props changed) Modified: stable/8/share/man/man4/psm.4 ============================================================================== --- stable/8/share/man/man4/psm.4 Wed Sep 8 07:30:46 2010 (r212313) +++ stable/8/share/man/man4/psm.4 Wed Sep 8 08:03:08 2010 (r212314) @@ -179,22 +179,6 @@ The driver has an internal variable whic the acceleration. Its value can be modified via the driver flag or via an ioctl call. -.Ss Device Number -The minor device number of the -.Nm -is made up of: -.Bd -literal -offset indent -minor = (`unit' << 1) | `non-blocking' -.Ed -.Pp -where `unit' is the device number (usually 0) and the `non-blocking' bit -is set to indicate ``do not block waiting for mouse input, -return immediately''. -The `non-blocking' bit should be set for \fIXFree86\fP, -therefore the minor device number usually used for \fIXFree86\fP is 1. -See -.Sx FILES -for device node names. .Sh DRIVER CONFIGURATION .Ss Kernel Configuration Options There are following kernel configuration options to control the @@ -670,8 +654,7 @@ movement counts as described in .It Pa /dev/psm0 `non-blocking' device node .It Pa /dev/bpsm0 -`blocking' device node under -.Em devfs . +`blocking' device node .El .Sh EXAMPLES In order to install the From owner-svn-src-stable@FreeBSD.ORG Wed Sep 8 09:51:04 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 45F8210656BD; Wed, 8 Sep 2010 09:51:04 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 34C2E8FC19; Wed, 8 Sep 2010 09:51:04 +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 o889p494004298; Wed, 8 Sep 2010 09:51:04 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o889p4Rd004296; Wed, 8 Sep 2010 09:51:04 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201009080951.o889p4Rd004296@svn.freebsd.org> From: Konstantin Belousov Date: Wed, 8 Sep 2010 09:51:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212315 - stable/8/share/man/man9 X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Sep 2010 09:51:04 -0000 Author: kib Date: Wed Sep 8 09:51:03 2010 New Revision: 212315 URL: http://svn.freebsd.org/changeset/base/212315 Log: MFC r212233: Document MAKEDEV_ETERNAL. Modified: stable/8/share/man/man9/make_dev.9 Directory Properties: stable/8/share/man/man9/ (props changed) Modified: stable/8/share/man/man9/make_dev.9 ============================================================================== --- stable/8/share/man/man9/make_dev.9 Wed Sep 8 08:03:08 2010 (r212314) +++ stable/8/share/man/man9/make_dev.9 Wed Sep 8 09:51:03 2010 (r212315) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 6, 2010 +.Dd September 5, 2010 .Dt MAKE_DEV 9 .Os .Sh NAME @@ -135,6 +135,7 @@ The following values are currently accep MAKEDEV_REF reference the created device MAKEDEV_NOWAIT do not sleep, may return NULL MAKEDEV_WAITOK allow the function to sleep to satisfy malloc +MAKEDEV_ETERNAL created device will be never destroyed .Ed .Pp The @@ -154,6 +155,18 @@ the device created is destroyed immediat drops his reference to cdev. .Pp The +.Dv MAKEDEV_ETERNAL +flag allows the kernel to not acquire some locks when translating system +calls into the cdevsw methods calls. +It is responsibility of the driver author to make sure that +.Fn destroy_dev +is never called on the returned cdev. +For the convenience, use the +.Dv MAKEDEV_ETERNAL_KLD +flag for the code that can be compiled into kernel or loaded +(and unloaded) as loadable module. +.Pp +The .Fn make_dev_cred function is equivalent to the call .Bd -literal -offset indent From owner-svn-src-stable@FreeBSD.ORG Wed Sep 8 09:53:50 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 64D2710656BD; Wed, 8 Sep 2010 09:53:50 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 53C258FC15; Wed, 8 Sep 2010 09:53:50 +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 o889roOu004589; Wed, 8 Sep 2010 09:53:50 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o889roO5004587; Wed, 8 Sep 2010 09:53:50 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201009080953.o889roO5004587@svn.freebsd.org> From: Konstantin Belousov Date: Wed, 8 Sep 2010 09:53:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212316 - stable/8/share/man/man4 X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Sep 2010 09:53:50 -0000 Author: kib Date: Wed Sep 8 09:53:50 2010 New Revision: 212316 URL: http://svn.freebsd.org/changeset/base/212316 Log: MFC r212234: Document "show cdev" command. Modified: stable/8/share/man/man4/ddb.4 Directory Properties: stable/8/share/man/man4/ (props changed) Modified: stable/8/share/man/man4/ddb.4 ============================================================================== --- stable/8/share/man/man4/ddb.4 Wed Sep 8 09:51:03 2010 (r212315) +++ stable/8/share/man/man4/ddb.4 Wed Sep 8 09:53:50 2010 (r212316) @@ -60,7 +60,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 24, 2010 +.Dd September 5, 2010 .Dt DDB 4 .Os .Sh NAME @@ -589,6 +589,12 @@ header file. Show brief information about the TTY subsystem. .\" .Pp +.It Ic show Cm cdev +Without argument, show the list of all created cdev's, consisting of devfs +node name and struct cdev address. +When address of cdev is supplied, show some internal devfs state of the cdev. +.\" +.Pp .It Ic show Cm conifhk Lists hooks currently waiting for completion in run_interrupt_driven_config_hooks(). From owner-svn-src-stable@FreeBSD.ORG Wed Sep 8 14:19:33 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5E4E510656DE; Wed, 8 Sep 2010 14:19:33 +0000 (UTC) (envelope-from zec@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 4D8978FC14; Wed, 8 Sep 2010 14:19:33 +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 o88EJXR2034199; Wed, 8 Sep 2010 14:19:33 GMT (envelope-from zec@svn.freebsd.org) Received: (from zec@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o88EJXDi034197; Wed, 8 Sep 2010 14:19:33 GMT (envelope-from zec@svn.freebsd.org) Message-Id: <201009081419.o88EJXDi034197@svn.freebsd.org> From: Marko Zec Date: Wed, 8 Sep 2010 14:19:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212318 - stable/8/sys/net X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Sep 2010 14:19:33 -0000 Author: zec Date: Wed Sep 8 14:19:33 2010 New Revision: 212318 URL: http://svn.freebsd.org/changeset/base/212318 Log: MFC r208743: Provide a macro for registering a virtualized sysctl handler for VNET opaque data. Modified: stable/8/sys/net/vnet.h Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/net/vnet.h ============================================================================== --- stable/8/sys/net/vnet.h Wed Sep 8 13:26:19 2010 (r212317) +++ stable/8/sys/net/vnet.h Wed Sep 8 14:19:33 2010 (r212318) @@ -236,6 +236,11 @@ int vnet_sysctl_handle_uint(SYSCTL_HANDL fmt, descr) \ SYSCTL_OID(parent, nbr, name, CTLFLAG_VNET|(access), ptr, arg, \ handler, fmt, descr) +#define SYSCTL_VNET_OPAQUE(parent, nbr, name, access, ptr, len, fmt, \ + descr) \ + SYSCTL_OID(parent, nbr, name, \ + CTLTYPE_OPAQUE|CTLFLAG_VNET|(access), ptr, len, \ + vnet_sysctl_handle_opaque, fmt, descr) #define SYSCTL_VNET_STRING(parent, nbr, name, access, arg, len, descr) \ SYSCTL_OID(parent, nbr, name, \ CTLTYPE_STRING|CTLFLAG_VNET|(access), \ @@ -389,6 +394,9 @@ do { \ fmt, descr) \ SYSCTL_PROC(parent, nbr, name, access, ptr, arg, handler, fmt, \ descr) +#define SYSCTL_VNET_OPAQUE(parent, nbr, name, access, ptr, len, fmt, \ + descr) \ + SYSCTL_OPAQUE(parent, nbr, name, access, ptr, len, fmt, descr) #define SYSCTL_VNET_STRING(parent, nbr, name, access, arg, len, descr) \ SYSCTL_STRING(parent, nbr, name, access, arg, len, descr) #define SYSCTL_VNET_STRUCT(parent, nbr, name, access, ptr, type, descr) \ From owner-svn-src-stable@FreeBSD.ORG Wed Sep 8 14:21:13 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 00BF310656A3; Wed, 8 Sep 2010 14:21:13 +0000 (UTC) (envelope-from zec@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id E2DFE8FC1D; Wed, 8 Sep 2010 14:21:12 +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 o88ELCYx034371; Wed, 8 Sep 2010 14:21:12 GMT (envelope-from zec@svn.freebsd.org) Received: (from zec@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o88ELCiO034368; Wed, 8 Sep 2010 14:21:12 GMT (envelope-from zec@svn.freebsd.org) Message-Id: <201009081421.o88ELCiO034368@svn.freebsd.org> From: Marko Zec Date: Wed, 8 Sep 2010 14:21:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212319 - stable/8/sys/netinet X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Sep 2010 14:21:13 -0000 Author: zec Date: Wed Sep 8 14:21:12 2010 New Revision: 212319 URL: http://svn.freebsd.org/changeset/base/212319 Log: MFC r208744: Virtualize the IPv4 multicast routing code. Submitted by: iprebeg Reviewed by: bms, bz, Pavlin Radoslavov Modified: stable/8/sys/netinet/ip_mroute.c stable/8/sys/netinet/ip_mroute.h stable/8/sys/netinet/pim_var.h Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/netinet/ip_mroute.c ============================================================================== --- stable/8/sys/netinet/ip_mroute.c Wed Sep 8 14:19:33 2010 (r212318) +++ stable/8/sys/netinet/ip_mroute.c Wed Sep 8 14:21:12 2010 (r212319) @@ -123,6 +123,9 @@ __FBSDID("$FreeBSD$"); #define VIFI_INVALID ((vifi_t) -1) #define M_HASCL(m) ((m)->m_flags & M_EXT) +static VNET_DEFINE(uint32_t, last_tv_sec); /* last time we processed this */ +#define V_last_tv_sec VNET(last_tv_sec) + static MALLOC_DEFINE(M_MRTABLE, "mroutetbl", "multicast forwarding cache"); /* @@ -141,21 +144,28 @@ static struct mtx mrouter_mtx; mtx_init(&mrouter_mtx, "IPv4 multicast forwarding", NULL, MTX_DEF) #define MROUTER_LOCK_DESTROY() mtx_destroy(&mrouter_mtx) -static struct mrtstat mrtstat; -SYSCTL_STRUCT(_net_inet_ip, OID_AUTO, mrtstat, CTLFLAG_RW, - &mrtstat, mrtstat, +static int ip_mrouter_cnt; /* # of vnets with active mrouters */ +static int ip_mrouter_unloading; /* Allow no more V_ip_mrouter sockets */ + +static VNET_DEFINE(struct mrtstat, mrtstat); +#define V_mrtstat VNET(mrtstat) +SYSCTL_VNET_STRUCT(_net_inet_ip, OID_AUTO, mrtstat, CTLFLAG_RW, + &VNET_NAME(mrtstat), mrtstat, "IPv4 Multicast Forwarding Statistics (struct mrtstat, " "netinet/ip_mroute.h)"); -static u_long mfchash; -#define MFCHASH(a, g) \ +static VNET_DEFINE(u_long, mfchash); +#define V_mfchash VNET(mfchash) +#define MFCHASH(a, g) \ ((((a).s_addr >> 20) ^ ((a).s_addr >> 10) ^ (a).s_addr ^ \ - ((g).s_addr >> 20) ^ ((g).s_addr >> 10) ^ (g).s_addr) & mfchash) -#define MFCHASHSIZE 256 + ((g).s_addr >> 20) ^ ((g).s_addr >> 10) ^ (g).s_addr) & V_mfchash) +#define MFCHASHSIZE 256 -static u_char *nexpire; /* 0..mfchashsize-1 */ -static u_long mfchashsize; /* Hash size */ -LIST_HEAD(mfchashhdr, mfc) *mfchashtbl; +static u_long mfchashsize; /* Hash size */ +static VNET_DEFINE(u_char *, nexpire); /* 0..mfchashsize-1 */ +#define V_nexpire VNET(nexpire) +static VNET_DEFINE(LIST_HEAD(mfchashhdr, mfc)*, mfchashtbl); +#define V_mfchashtbl VNET(mfchashtbl) static struct mtx mfc_mtx; #define MFC_LOCK() mtx_lock(&mfc_mtx) @@ -165,10 +175,12 @@ static struct mtx mfc_mtx; mtx_init(&mfc_mtx, "IPv4 multicast forwarding cache", NULL, MTX_DEF) #define MFC_LOCK_DESTROY() mtx_destroy(&mfc_mtx) -static vifi_t numvifs; -static struct vif viftable[MAXVIFS]; -SYSCTL_OPAQUE(_net_inet_ip, OID_AUTO, viftable, CTLFLAG_RD, - &viftable, sizeof(viftable), "S,vif[MAXVIFS]", +static VNET_DEFINE(vifi_t, numvifs); +#define V_numvifs VNET(numvifs) +static VNET_DEFINE(struct vif, viftable[MAXVIFS]); +#define V_viftable VNET(viftable) +SYSCTL_VNET_OPAQUE(_net_inet_ip, OID_AUTO, viftable, CTLFLAG_RD, + &VNET_NAME(viftable), sizeof(V_viftable), "S,vif[MAXVIFS]", "IPv4 Multicast Interfaces (struct vif[MAXVIFS], netinet/ip_mroute.h)"); static struct mtx vif_mtx; @@ -181,7 +193,9 @@ static struct mtx vif_mtx; static eventhandler_tag if_detach_event_tag = NULL; -static struct callout expire_upcalls_ch; +static VNET_DEFINE(struct callout, expire_upcalls_ch); +#define V_expire_upcalls_ch VNET(expire_upcalls_ch) + #define EXPIRE_TIMEOUT (hz / 4) /* 4x / second */ #define UPCALL_EXPIRE 6 /* number of timeouts */ @@ -193,25 +207,32 @@ static MALLOC_DEFINE(M_BWMETER, "bwmeter * Pending timeouts are stored in a hash table, the key being the * expiration time. Periodically, the entries are analysed and processed. */ -#define BW_METER_BUCKETS 1024 -static struct bw_meter *bw_meter_timers[BW_METER_BUCKETS]; -static struct callout bw_meter_ch; -#define BW_METER_PERIOD (hz) /* periodical handling of bw meters */ +#define BW_METER_BUCKETS 1024 +static VNET_DEFINE(struct bw_meter*, bw_meter_timers[BW_METER_BUCKETS]); +#define V_bw_meter_timers VNET(bw_meter_timers) +static VNET_DEFINE(struct callout, bw_meter_ch); +#define V_bw_meter_ch VNET(bw_meter_ch) +#define BW_METER_PERIOD (hz) /* periodical handling of bw meters */ /* * Pending upcalls are stored in a vector which is flushed when * full, or periodically */ -static struct bw_upcall bw_upcalls[BW_UPCALLS_MAX]; -static u_int bw_upcalls_n; /* # of pending upcalls */ -static struct callout bw_upcalls_ch; +static VNET_DEFINE(struct bw_upcall, bw_upcalls[BW_UPCALLS_MAX]); +#define V_bw_upcalls VNET(bw_upcalls) +static VNET_DEFINE(u_int, bw_upcalls_n); /* # of pending upcalls */ +#define V_bw_upcalls_n VNET(bw_upcalls_n) +static VNET_DEFINE(struct callout, bw_upcalls_ch); +#define V_bw_upcalls_ch VNET(bw_upcalls_ch) + #define BW_UPCALLS_PERIOD (hz) /* periodical flush of bw upcalls */ -static struct pimstat pimstat; +static VNET_DEFINE(struct pimstat, pimstat); +#define V_pimstat VNET(pimstat) SYSCTL_NODE(_net_inet, IPPROTO_PIM, pim, CTLFLAG_RW, 0, "PIM"); -SYSCTL_STRUCT(_net_inet_pim, PIMCTL_STATS, stats, CTLFLAG_RD, - &pimstat, pimstat, +SYSCTL_VNET_STRUCT(_net_inet_pim, PIMCTL_STATS, stats, CTLFLAG_RD, + &VNET_NAME(pimstat), pimstat, "PIM Statistics (struct pimstat, netinet/pim_var.h)"); static u_long pim_squelch_wholepkt = 0; @@ -277,8 +298,10 @@ static struct pim_encap_pimhdr pim_encap 0 /* flags */ }; -static struct ifnet multicast_register_if; -static vifi_t reg_vif_num = VIFI_INVALID; +static VNET_DEFINE(vifi_t, reg_vif_num) = VIFI_INVALID; +#define V_reg_vif_num VNET(reg_vif_num) +static VNET_DEFINE(struct ifnet, multicast_register_if); +#define V_multicast_register_if VNET(multicast_register_if) /* * Private variables. @@ -346,9 +369,10 @@ static const uint32_t mrt_api_support = MRT_MFC_FLAGS_BORDER_VIF | MRT_MFC_RP | MRT_MFC_BW_UPCALL); -static uint32_t mrt_api_config = 0; - -static int pim_assert_enabled; +static VNET_DEFINE(uint32_t, mrt_api_config); +#define V_mrt_api_config VNET(mrt_api_config) +static VNET_DEFINE(int, pim_assert_enabled); +#define V_pim_assert_enabled VNET(pim_assert_enabled) static struct timeval pim_assert_interval = { 3, 0 }; /* Rate limit */ /* @@ -362,7 +386,7 @@ mfc_find(struct in_addr *o, struct in_ad MFC_LOCK_ASSERT(); - LIST_FOREACH(rt, &mfchashtbl[MFCHASH(*o, *g)], mfc_hash) { + LIST_FOREACH(rt, &V_mfchashtbl[MFCHASH(*o, *g)], mfc_hash) { if (in_hosteq(rt->mfc_origin, *o) && in_hosteq(rt->mfc_mcastgrp, *g) && TAILQ_EMPTY(&rt->mfc_stall)) @@ -421,7 +445,7 @@ X_ip_mrouter_set(struct socket *so, stru * select data size depending on API version. */ if (sopt->sopt_name == MRT_ADD_MFC && - mrt_api_config & MRT_API_FLAGS_ALL) { + V_mrt_api_config & MRT_API_FLAGS_ALL) { error = sooptcopyin(sopt, &mfc, sizeof(struct mfcctl2), sizeof(struct mfcctl2)); } else { @@ -486,8 +510,8 @@ X_ip_mrouter_get(struct socket *so, stru break; case MRT_ASSERT: - error = sooptcopyout(sopt, &pim_assert_enabled, - sizeof pim_assert_enabled); + error = sooptcopyout(sopt, &V_pim_assert_enabled, + sizeof V_pim_assert_enabled); break; case MRT_API_SUPPORT: @@ -495,7 +519,7 @@ X_ip_mrouter_get(struct socket *so, stru break; case MRT_API_CONFIG: - error = sooptcopyout(sopt, &mrt_api_config, sizeof mrt_api_config); + error = sooptcopyout(sopt, &V_mrt_api_config, sizeof V_mrt_api_config); break; default: @@ -568,36 +592,21 @@ get_vif_cnt(struct sioc_vif_req *req) vifi_t vifi = req->vifi; VIF_LOCK(); - if (vifi >= numvifs) { + if (vifi >= V_numvifs) { VIF_UNLOCK(); return EINVAL; } - req->icount = viftable[vifi].v_pkt_in; - req->ocount = viftable[vifi].v_pkt_out; - req->ibytes = viftable[vifi].v_bytes_in; - req->obytes = viftable[vifi].v_bytes_out; + req->icount = V_viftable[vifi].v_pkt_in; + req->ocount = V_viftable[vifi].v_pkt_out; + req->ibytes = V_viftable[vifi].v_bytes_in; + req->obytes = V_viftable[vifi].v_bytes_out; VIF_UNLOCK(); return 0; } static void -ip_mrouter_reset(void) -{ - - pim_assert_enabled = 0; - mrt_api_config = 0; - - callout_init(&expire_upcalls_ch, CALLOUT_MPSAFE); - - bw_upcalls_n = 0; - bzero((caddr_t)bw_meter_timers, sizeof(bw_meter_timers)); - callout_init(&bw_upcalls_ch, CALLOUT_MPSAFE); - callout_init(&bw_meter_ch, CALLOUT_MPSAFE); -} - -static void if_detached_event(void *arg __unused, struct ifnet *ifp) { vifi_t vifi; @@ -621,12 +630,12 @@ if_detached_event(void *arg __unused, st * 3. Expire any matching multicast forwarding cache entries. * 4. Free vif state. This should disable ALLMULTI on the interface. */ - for (vifi = 0; vifi < numvifs; vifi++) { - if (viftable[vifi].v_ifp != ifp) + for (vifi = 0; vifi < V_numvifs; vifi++) { + if (V_viftable[vifi].v_ifp != ifp) continue; for (i = 0; i < mfchashsize; i++) { struct mfc *rt, *nrt; - for (rt = LIST_FIRST(&mfchashtbl[i]); rt; rt = nrt) { + for (rt = LIST_FIRST(&V_mfchashtbl[i]); rt; rt = nrt) { nrt = LIST_NEXT(rt, mfc_hash); if (rt->mfc_parent == vifi) { expire_mfc(rt); @@ -660,27 +669,28 @@ ip_mrouter_init(struct socket *so, int v MROUTER_LOCK(); - if (V_ip_mrouter != NULL) { + if (ip_mrouter_unloading) { MROUTER_UNLOCK(); - return EADDRINUSE; + return ENOPROTOOPT; } - if_detach_event_tag = EVENTHANDLER_REGISTER(ifnet_departure_event, - if_detached_event, NULL, EVENTHANDLER_PRI_ANY); - if (if_detach_event_tag == NULL) { + if (V_ip_mrouter != NULL) { MROUTER_UNLOCK(); - return (ENOMEM); + return EADDRINUSE; } - mfchashtbl = hashinit_flags(mfchashsize, M_MRTABLE, &mfchash, HASH_NOWAIT); - - callout_reset(&expire_upcalls_ch, EXPIRE_TIMEOUT, expire_upcalls, NULL); + V_mfchashtbl = hashinit_flags(mfchashsize, M_MRTABLE, &V_mfchash, + HASH_NOWAIT); - callout_reset(&bw_upcalls_ch, BW_UPCALLS_PERIOD, - expire_bw_upcalls_send, NULL); - callout_reset(&bw_meter_ch, BW_METER_PERIOD, expire_bw_meter_process, NULL); + callout_reset(&V_expire_upcalls_ch, EXPIRE_TIMEOUT, expire_upcalls, + curvnet); + callout_reset(&V_bw_upcalls_ch, BW_UPCALLS_PERIOD, expire_bw_upcalls_send, + curvnet); + callout_reset(&V_bw_meter_ch, BW_METER_PERIOD, expire_bw_meter_process, + curvnet); V_ip_mrouter = so; + ip_mrouter_cnt++; MROUTER_UNLOCK(); @@ -711,7 +721,8 @@ X_ip_mrouter_done(void) * Detach/disable hooks to the reset of the system. */ V_ip_mrouter = NULL; - mrt_api_config = 0; + ip_mrouter_cnt--; + V_mrt_api_config = 0; VIF_LOCK(); @@ -719,29 +730,27 @@ X_ip_mrouter_done(void) * For each phyint in use, disable promiscuous reception of all IP * multicasts. */ - for (vifi = 0; vifi < numvifs; vifi++) { - if (!in_nullhost(viftable[vifi].v_lcl_addr) && - !(viftable[vifi].v_flags & (VIFF_TUNNEL | VIFF_REGISTER))) { + for (vifi = 0; vifi < V_numvifs; vifi++) { + if (!in_nullhost(V_viftable[vifi].v_lcl_addr) && + !(V_viftable[vifi].v_flags & (VIFF_TUNNEL | VIFF_REGISTER))) { struct sockaddr_in *so = (struct sockaddr_in *)&(ifr.ifr_addr); so->sin_len = sizeof(struct sockaddr_in); so->sin_family = AF_INET; so->sin_addr.s_addr = INADDR_ANY; - ifp = viftable[vifi].v_ifp; + ifp = V_viftable[vifi].v_ifp; if_allmulti(ifp, 0); } } - bzero((caddr_t)viftable, sizeof(viftable)); - numvifs = 0; - pim_assert_enabled = 0; - + bzero((caddr_t)V_viftable, sizeof(V_viftable)); + V_numvifs = 0; + V_pim_assert_enabled = 0; + VIF_UNLOCK(); - EVENTHANDLER_DEREGISTER(ifnet_departure_event, if_detach_event_tag); - - callout_stop(&expire_upcalls_ch); - callout_stop(&bw_upcalls_ch); - callout_stop(&bw_meter_ch); + callout_stop(&V_expire_upcalls_ch); + callout_stop(&V_bw_upcalls_ch); + callout_stop(&V_bw_meter_ch); MFC_LOCK(); @@ -751,22 +760,22 @@ X_ip_mrouter_done(void) */ for (i = 0; i < mfchashsize; i++) { struct mfc *rt, *nrt; - for (rt = LIST_FIRST(&mfchashtbl[i]); rt; rt = nrt) { + for (rt = LIST_FIRST(&V_mfchashtbl[i]); rt; rt = nrt) { nrt = LIST_NEXT(rt, mfc_hash); expire_mfc(rt); } } - free(mfchashtbl, M_MRTABLE); - mfchashtbl = NULL; + free(V_mfchashtbl, M_MRTABLE); + V_mfchashtbl = NULL; - bzero(nexpire, sizeof(nexpire[0]) * mfchashsize); + bzero(V_nexpire, sizeof(V_nexpire[0]) * mfchashsize); - bw_upcalls_n = 0; - bzero(bw_meter_timers, sizeof(bw_meter_timers)); + V_bw_upcalls_n = 0; + bzero(V_bw_meter_timers, sizeof(V_bw_meter_timers)); MFC_UNLOCK(); - reg_vif_num = VIFI_INVALID; + V_reg_vif_num = VIFI_INVALID; MROUTER_UNLOCK(); @@ -784,7 +793,7 @@ set_assert(int i) if ((i != 1) && (i != 0)) return EINVAL; - pim_assert_enabled = i; + V_pim_assert_enabled = i; return 0; } @@ -804,11 +813,11 @@ set_api_config(uint32_t *apival) * - pim_assert is not enabled * - the MFC table is empty */ - if (numvifs > 0) { + if (V_numvifs > 0) { *apival = 0; return EPERM; } - if (pim_assert_enabled) { + if (V_pim_assert_enabled) { *apival = 0; return EPERM; } @@ -816,7 +825,7 @@ set_api_config(uint32_t *apival) MFC_LOCK(); for (i = 0; i < mfchashsize; i++) { - if (LIST_FIRST(&mfchashtbl[i]) != NULL) { + if (LIST_FIRST(&V_mfchashtbl[i]) != NULL) { *apival = 0; return EPERM; } @@ -824,8 +833,8 @@ set_api_config(uint32_t *apival) MFC_UNLOCK(); - mrt_api_config = *apival & mrt_api_support; - *apival = mrt_api_config; + V_mrt_api_config = *apival & mrt_api_support; + *apival = V_mrt_api_config; return 0; } @@ -836,7 +845,7 @@ set_api_config(uint32_t *apival) static int add_vif(struct vifctl *vifcp) { - struct vif *vifp = viftable + vifcp->vifc_vifi; + struct vif *vifp = V_viftable + vifcp->vifc_vifi; struct sockaddr_in sin = {sizeof sin, AF_INET}; struct ifaddr *ifa; struct ifnet *ifp; @@ -886,12 +895,12 @@ add_vif(struct vifctl *vifcp) VIF_UNLOCK(); return EOPNOTSUPP; } else if (vifcp->vifc_flags & VIFF_REGISTER) { - ifp = &multicast_register_if; + ifp = &V_multicast_register_if; CTR2(KTR_IPMF, "%s: add register vif for ifp %p", __func__, ifp); - if (reg_vif_num == VIFI_INVALID) { - if_initname(&multicast_register_if, "register_vif", 0); - multicast_register_if.if_flags = IFF_LOOPBACK; - reg_vif_num = vifcp->vifc_vifi; + if (V_reg_vif_num == VIFI_INVALID) { + if_initname(&V_multicast_register_if, "register_vif", 0); + V_multicast_register_if.if_flags = IFF_LOOPBACK; + V_reg_vif_num = vifcp->vifc_vifi; } } else { /* Make sure the interface supports multicast */ if ((ifp->if_flags & IFF_MULTICAST) == 0) { @@ -920,8 +929,8 @@ add_vif(struct vifctl *vifcp) bzero(&vifp->v_route, sizeof(vifp->v_route)); /* Adjust numvifs up if the vifi is higher than numvifs */ - if (numvifs <= vifcp->vifc_vifi) - numvifs = vifcp->vifc_vifi + 1; + if (V_numvifs <= vifcp->vifc_vifi) + V_numvifs = vifcp->vifc_vifi + 1; VIF_UNLOCK(); @@ -942,10 +951,10 @@ del_vif_locked(vifi_t vifi) VIF_LOCK_ASSERT(); - if (vifi >= numvifs) { + if (vifi >= V_numvifs) { return EINVAL; } - vifp = &viftable[vifi]; + vifp = &V_viftable[vifi]; if (in_nullhost(vifp->v_lcl_addr)) { return EADDRNOTAVAIL; } @@ -954,17 +963,17 @@ del_vif_locked(vifi_t vifi) if_allmulti(vifp->v_ifp, 0); if (vifp->v_flags & VIFF_REGISTER) - reg_vif_num = VIFI_INVALID; + V_reg_vif_num = VIFI_INVALID; bzero((caddr_t)vifp, sizeof (*vifp)); CTR2(KTR_IPMF, "%s: delete vif %d", __func__, (int)vifi); /* Adjust numvifs down */ - for (vifi = numvifs; vifi > 0; vifi--) - if (!in_nullhost(viftable[vifi-1].v_lcl_addr)) + for (vifi = V_numvifs; vifi > 0; vifi--) + if (!in_nullhost(V_viftable[vifi-1].v_lcl_addr)) break; - numvifs = vifi; + V_numvifs = vifi; return 0; } @@ -990,13 +999,13 @@ update_mfc_params(struct mfc *rt, struct int i; rt->mfc_parent = mfccp->mfcc_parent; - for (i = 0; i < numvifs; i++) { + for (i = 0; i < V_numvifs; i++) { rt->mfc_ttls[i] = mfccp->mfcc_ttls[i]; - rt->mfc_flags[i] = mfccp->mfcc_flags[i] & mrt_api_config & + rt->mfc_flags[i] = mfccp->mfcc_flags[i] & V_mrt_api_config & MRT_MFC_FLAGS_ALL; } /* set the RP address */ - if (mrt_api_config & MRT_MFC_RP) + if (V_mrt_api_config & MRT_MFC_RP) rt->mfc_rp = mfccp->mfcc_rp; else rt->mfc_rp.s_addr = INADDR_ANY; @@ -1070,7 +1079,7 @@ add_mfc(struct mfcctl2 *mfccp) */ nstl = 0; hash = MFCHASH(mfccp->mfcc_origin, mfccp->mfcc_mcastgrp); - LIST_FOREACH(rt, &mfchashtbl[hash], mfc_hash) { + LIST_FOREACH(rt, &V_mfchashtbl[hash], mfc_hash) { if (in_hosteq(rt->mfc_origin, mfccp->mfcc_origin) && in_hosteq(rt->mfc_mcastgrp, mfccp->mfcc_mcastgrp) && !TAILQ_EMPTY(&rt->mfc_stall)) { @@ -1085,7 +1094,7 @@ add_mfc(struct mfcctl2 *mfccp) init_mfc_params(rt, mfccp); rt->mfc_expire = 0; /* Don't clean this guy up */ - nexpire[hash]--; + V_nexpire[hash]--; /* Free queued packets, but attempt to forward them first. */ TAILQ_FOREACH_SAFE(rte, &rt->mfc_stall, rte_link, nrte) { @@ -1104,12 +1113,12 @@ add_mfc(struct mfcctl2 *mfccp) */ if (nstl == 0) { CTR1(KTR_IPMF, "%s: adding mfc w/o upcall", __func__); - LIST_FOREACH(rt, &mfchashtbl[hash], mfc_hash) { + LIST_FOREACH(rt, &V_mfchashtbl[hash], mfc_hash) { if (in_hosteq(rt->mfc_origin, mfccp->mfcc_origin) && in_hosteq(rt->mfc_mcastgrp, mfccp->mfcc_mcastgrp)) { init_mfc_params(rt, mfccp); if (rt->mfc_expire) - nexpire[hash]--; + V_nexpire[hash]--; rt->mfc_expire = 0; break; /* XXX */ } @@ -1131,7 +1140,7 @@ add_mfc(struct mfcctl2 *mfccp) rt->mfc_bw_meter = NULL; /* insert new entry at head of hash chain */ - LIST_INSERT_HEAD(&mfchashtbl[hash], rt, mfc_hash); + LIST_INSERT_HEAD(&V_mfchashtbl[hash], rt, mfc_hash); } } @@ -1238,7 +1247,7 @@ X_ip_mforward(struct ip *ip, struct ifne VIF_LOCK(); MFC_LOCK(); - if (imo && ((vifi = imo->imo_multicast_vif) < numvifs)) { + if (imo && ((vifi = imo->imo_multicast_vif) < V_numvifs)) { if (ip->ip_ttl < MAXTTL) ip->ip_ttl++; /* compensate for -1 in *_send routines */ error = ip_mdq(m, ifp, NULL, vifi); @@ -1310,7 +1319,7 @@ X_ip_mforward(struct ip *ip, struct ifne /* is there an upcall waiting for this flow ? */ hash = MFCHASH(ip->ip_src, ip->ip_dst); - LIST_FOREACH(rt, &mfchashtbl[hash], mfc_hash) { + LIST_FOREACH(rt, &V_mfchashtbl[hash], mfc_hash) { if (in_hosteq(ip->ip_src, rt->mfc_origin) && in_hosteq(ip->ip_dst, rt->mfc_mcastgrp) && !TAILQ_EMPTY(&rt->mfc_stall)) @@ -1327,10 +1336,10 @@ X_ip_mforward(struct ip *ip, struct ifne * Locate the vifi for the incoming interface for this packet. * If none found, drop packet. */ - for (vifi = 0; vifi < numvifs && - viftable[vifi].v_ifp != ifp; vifi++) + for (vifi = 0; vifi < V_numvifs && + V_viftable[vifi].v_ifp != ifp; vifi++) ; - if (vifi >= numvifs) /* vif not found, drop packet */ + if (vifi >= V_numvifs) /* vif not found, drop packet */ goto non_fatal; /* no upcall, so make a new entry */ @@ -1373,8 +1382,8 @@ fail: rt->mfc_origin.s_addr = ip->ip_src.s_addr; rt->mfc_mcastgrp.s_addr = ip->ip_dst.s_addr; rt->mfc_expire = UPCALL_EXPIRE; - nexpire[hash]++; - for (i = 0; i < numvifs; i++) { + V_nexpire[hash]++; + for (i = 0; i < V_numvifs; i++) { rt->mfc_ttls[i] = 0; rt->mfc_flags[i] = 0; } @@ -1394,7 +1403,7 @@ fail: rt->mfc_nstall = 0; /* link into table */ - LIST_INSERT_HEAD(&mfchashtbl[hash], rt, mfc_hash); + LIST_INSERT_HEAD(&V_mfchashtbl[hash], rt, mfc_hash); TAILQ_INSERT_HEAD(&rt->mfc_stall, rte, rte_link); rt->mfc_nstall++; @@ -1427,19 +1436,21 @@ non_fatal: * Clean up the cache entry if upcall is not serviced */ static void -expire_upcalls(void *unused) +expire_upcalls(void *arg) { int i; + CURVNET_SET((struct vnet *) arg); + MFC_LOCK(); for (i = 0; i < mfchashsize; i++) { struct mfc *rt, *nrt; - if (nexpire[i] == 0) + if (V_nexpire[i] == 0) continue; - for (rt = LIST_FIRST(&mfchashtbl[i]); rt; rt = nrt) { + for (rt = LIST_FIRST(&V_mfchashtbl[i]); rt; rt = nrt) { nrt = LIST_NEXT(rt, mfc_hash); if (TAILQ_EMPTY(&rt->mfc_stall)) @@ -1469,7 +1480,10 @@ expire_upcalls(void *unused) MFC_UNLOCK(); - callout_reset(&expire_upcalls_ch, EXPIRE_TIMEOUT, expire_upcalls, NULL); + callout_reset(&V_expire_upcalls_ch, EXPIRE_TIMEOUT, expire_upcalls, + curvnet); + + CURVNET_RESTORE(); } /* @@ -1489,11 +1503,11 @@ ip_mdq(struct mbuf *m, struct ifnet *ifp * * (since vifi_t is u_short, -1 becomes MAXUSHORT, which > numvifs.) */ - if (xmt_vif < numvifs) { - if (viftable[xmt_vif].v_flags & VIFF_REGISTER) - pim_register_send(ip, viftable + xmt_vif, m, rt); + if (xmt_vif < V_numvifs) { + if (V_viftable[xmt_vif].v_flags & VIFF_REGISTER) + pim_register_send(ip, V_viftable + xmt_vif, m, rt); else - phyint_send(ip, viftable + xmt_vif, m); + phyint_send(ip, V_viftable + xmt_vif, m); return 1; } @@ -1501,9 +1515,9 @@ ip_mdq(struct mbuf *m, struct ifnet *ifp * Don't forward if it didn't arrive from the parent vif for its origin. */ vifi = rt->mfc_parent; - if ((vifi >= numvifs) || (viftable[vifi].v_ifp != ifp)) { + if ((vifi >= V_numvifs) || (V_viftable[vifi].v_ifp != ifp)) { CTR4(KTR_IPMF, "%s: rx on wrong ifp %p (vifi %d, v_ifp %p)", - __func__, ifp, (int)vifi, viftable[vifi].v_ifp); + __func__, ifp, (int)vifi, V_viftable[vifi].v_ifp); MRTSTAT_INC(mrts_wrong_if); ++rt->mfc_wrong_if; /* @@ -1514,15 +1528,17 @@ ip_mdq(struct mbuf *m, struct ifnet *ifp * can complete the SPT switch, regardless of the type * of the iif (broadcast media, GRE tunnel, etc). */ - if (pim_assert_enabled && (vifi < numvifs) && viftable[vifi].v_ifp) { + if (V_pim_assert_enabled && (vifi < V_numvifs) && + V_viftable[vifi].v_ifp) { - if (ifp == &multicast_register_if) + if (ifp == &V_multicast_register_if) PIMSTAT_INC(pims_rcv_registers_wrongiif); /* Get vifi for the incoming packet */ - for (vifi=0; vifi < numvifs && viftable[vifi].v_ifp != ifp; vifi++) + for (vifi = 0; vifi < V_numvifs && V_viftable[vifi].v_ifp != ifp; + vifi++) ; - if (vifi >= numvifs) + if (vifi >= V_numvifs) return 0; /* The iif is not found: ignore the packet. */ if (rt->mfc_flags[vifi] & MRT_MFC_FLAGS_DISABLE_WRONGVIF) @@ -1559,12 +1575,12 @@ ip_mdq(struct mbuf *m, struct ifnet *ifp /* If I sourced this packet, it counts as output, else it was input. */ - if (in_hosteq(ip->ip_src, viftable[vifi].v_lcl_addr)) { - viftable[vifi].v_pkt_out++; - viftable[vifi].v_bytes_out += plen; + if (in_hosteq(ip->ip_src, V_viftable[vifi].v_lcl_addr)) { + V_viftable[vifi].v_pkt_out++; + V_viftable[vifi].v_bytes_out += plen; } else { - viftable[vifi].v_pkt_in++; - viftable[vifi].v_bytes_in += plen; + V_viftable[vifi].v_pkt_in++; + V_viftable[vifi].v_bytes_in += plen; } rt->mfc_pkt_cnt++; rt->mfc_byte_cnt += plen; @@ -1575,14 +1591,14 @@ ip_mdq(struct mbuf *m, struct ifnet *ifp * - the ttl exceeds the vif's threshold * - there are group members downstream on interface */ - for (vifi = 0; vifi < numvifs; vifi++) + for (vifi = 0; vifi < V_numvifs; vifi++) if ((rt->mfc_ttls[vifi] > 0) && (ip->ip_ttl > rt->mfc_ttls[vifi])) { - viftable[vifi].v_pkt_out++; - viftable[vifi].v_bytes_out += plen; - if (viftable[vifi].v_flags & VIFF_REGISTER) - pim_register_send(ip, viftable + vifi, m, rt); + V_viftable[vifi].v_pkt_out++; + V_viftable[vifi].v_bytes_out += plen; + if (V_viftable[vifi].v_flags & VIFF_REGISTER) + pim_register_send(ip, V_viftable + vifi, m, rt); else - phyint_send(ip, viftable + vifi, m); + phyint_send(ip, V_viftable + vifi, m); } /* @@ -1614,7 +1630,7 @@ X_legal_vif_num(int vif) return (ret); VIF_LOCK(); - if (vif < numvifs) + if (vif < V_numvifs) ret = 1; VIF_UNLOCK(); @@ -1634,8 +1650,8 @@ X_ip_mcast_src(int vifi) return (addr); VIF_LOCK(); - if (vifi < numvifs) - addr = viftable[vifi].v_lcl_addr.s_addr; + if (vifi < V_numvifs) + addr = V_viftable[vifi].v_lcl_addr.s_addr; VIF_UNLOCK(); return (addr); @@ -1688,7 +1704,7 @@ send_packet(struct vif *vifp, struct mbu */ error = ip_output(m, NULL, &vifp->v_route, IP_FORWARDING, &imo, NULL); CTR3(KTR_IPMF, "%s: vif %td err %d", __func__, - (ptrdiff_t)(vifp - viftable), error); + (ptrdiff_t)(vifp - V_viftable), error); } /* @@ -1757,7 +1773,7 @@ add_bw_upcall(struct bw_upcall *req) struct bw_meter *x; uint32_t flags; - if (!(mrt_api_config & MRT_MFC_BW_UPCALL)) + if (!(V_mrt_api_config & MRT_MFC_BW_UPCALL)) return EOPNOTSUPP; /* Test if the flags are valid */ @@ -1845,7 +1861,7 @@ del_bw_upcall(struct bw_upcall *req) struct mfc *mfc; struct bw_meter *x; - if (!(mrt_api_config & MRT_MFC_BW_UPCALL)) + if (!(V_mrt_api_config & MRT_MFC_BW_UPCALL)) return EOPNOTSUPP; MFC_LOCK(); @@ -2013,13 +2029,13 @@ bw_meter_prepare_upcall(struct bw_meter /* * If there are too many pending upcalls, deliver them now */ - if (bw_upcalls_n >= BW_UPCALLS_MAX) + if (V_bw_upcalls_n >= BW_UPCALLS_MAX) bw_upcalls_send(); /* * Set the bw_upcall entry */ - u = &bw_upcalls[bw_upcalls_n++]; + u = &V_bw_upcalls[V_bw_upcalls_n++]; u->bu_src = x->bm_mfc->mfc_origin; u->bu_dst = x->bm_mfc->mfc_mcastgrp; u->bu_threshold.b_time = x->bm_threshold.b_time; @@ -2046,7 +2062,7 @@ static void bw_upcalls_send(void) { struct mbuf *m; - int len = bw_upcalls_n * sizeof(bw_upcalls[0]); + int len = V_bw_upcalls_n * sizeof(V_bw_upcalls[0]); struct sockaddr_in k_igmpsrc = { sizeof k_igmpsrc, AF_INET }; static struct igmpmsg igmpmsg = { 0, /* unused1 */ 0, /* unused2 */ @@ -2059,10 +2075,10 @@ bw_upcalls_send(void) MFC_LOCK_ASSERT(); - if (bw_upcalls_n == 0) + if (V_bw_upcalls_n == 0) return; /* No pending upcalls */ - bw_upcalls_n = 0; + V_bw_upcalls_n = 0; /* * Allocate a new mbuf, initialize it with the header and @@ -2076,7 +2092,7 @@ bw_upcalls_send(void) m->m_len = m->m_pkthdr.len = 0; m_copyback(m, 0, sizeof(struct igmpmsg), (caddr_t)&igmpmsg); - m_copyback(m, sizeof(struct igmpmsg), len, (caddr_t)&bw_upcalls[0]); + m_copyback(m, sizeof(struct igmpmsg), len, (caddr_t)&V_bw_upcalls[0]); /* * Send the upcalls @@ -2129,8 +2145,8 @@ schedule_bw_meter(struct bw_meter *x, st * Compute the timeout hash value and insert the entry */ BW_METER_TIMEHASH(x, time_hash); - x->bm_time_next = bw_meter_timers[time_hash]; - bw_meter_timers[time_hash] = x; + x->bm_time_next = V_bw_meter_timers[time_hash]; + V_bw_meter_timers[time_hash] = x; x->bm_time_hash = time_hash; } @@ -2156,7 +2172,7 @@ unschedule_bw_meter(struct bw_meter *x) if (time_hash >= BW_METER_BUCKETS) return; /* Entry was not scheduled */ - for (prev = NULL, tmp = bw_meter_timers[time_hash]; + for (prev = NULL, tmp = V_bw_meter_timers[time_hash]; tmp != NULL; prev = tmp, tmp = tmp->bm_time_next) if (tmp == x) break; @@ -2167,7 +2183,7 @@ unschedule_bw_meter(struct bw_meter *x) if (prev != NULL) prev->bm_time_next = x->bm_time_next; else - bw_meter_timers[time_hash] = x->bm_time_next; + V_bw_meter_timers[time_hash] = x->bm_time_next; x->bm_time_next = NULL; x->bm_time_hash = BW_METER_BUCKETS; @@ -2186,18 +2202,16 @@ unschedule_bw_meter(struct bw_meter *x) static void bw_meter_process() { - static uint32_t last_tv_sec; /* last time we processed this */ - uint32_t loops; int i; struct timeval now, process_endtime; microtime(&now); - if (last_tv_sec == now.tv_sec) + if (V_last_tv_sec == now.tv_sec) return; /* nothing to do */ - loops = now.tv_sec - last_tv_sec; - last_tv_sec = now.tv_sec; + loops = now.tv_sec - V_last_tv_sec; + V_last_tv_sec = now.tv_sec; if (loops > BW_METER_BUCKETS) loops = BW_METER_BUCKETS; @@ -2214,8 +2228,8 @@ bw_meter_process() i = 0; /* Disconnect the list of bw_meter entries from the bin */ - tmp_list = bw_meter_timers[i]; - bw_meter_timers[i] = NULL; + tmp_list = V_bw_meter_timers[i]; + V_bw_meter_timers[i] = NULL; /* Process the list of bw_meter entries */ while (tmp_list != NULL) { @@ -2238,8 +2252,8 @@ bw_meter_process() if (++time_hash >= BW_METER_BUCKETS) time_hash = 0; } - x->bm_time_next = bw_meter_timers[time_hash]; - bw_meter_timers[time_hash] = x; + x->bm_time_next = V_bw_meter_timers[time_hash]; + V_bw_meter_timers[time_hash] = x; x->bm_time_hash = time_hash; continue; @@ -2273,14 +2287,17 @@ bw_meter_process() * A periodic function for sending all upcalls that are pending delivery */ static void -expire_bw_upcalls_send(void *unused) +expire_bw_upcalls_send(void *arg) { + CURVNET_SET((struct vnet *) arg); + MFC_LOCK(); bw_upcalls_send(); MFC_UNLOCK(); - callout_reset(&bw_upcalls_ch, BW_UPCALLS_PERIOD, - expire_bw_upcalls_send, NULL); + callout_reset(&V_bw_upcalls_ch, BW_UPCALLS_PERIOD, expire_bw_upcalls_send, + curvnet); + CURVNET_RESTORE(); } /* @@ -2288,12 +2305,16 @@ expire_bw_upcalls_send(void *unused) * table for processing all "<=" bw_meter entries. */ static void -expire_bw_meter_process(void *unused) +expire_bw_meter_process(void *arg) { - if (mrt_api_config & MRT_MFC_BW_UPCALL) + CURVNET_SET((struct vnet *) arg); + + if (V_mrt_api_config & MRT_MFC_BW_UPCALL) bw_meter_process(); - callout_reset(&bw_meter_ch, BW_METER_PERIOD, expire_bw_meter_process, NULL); + callout_reset(&V_bw_meter_ch, BW_METER_PERIOD, expire_bw_meter_process, + curvnet); + CURVNET_RESTORE(); } /* @@ -2314,7 +2335,7 @@ pim_register_send(struct ip *ip, struct * Do not send IGMP_WHOLEPKT notifications to userland, if the * rendezvous point was unspecified, and we were told not to. */ - if (pim_squelch_wholepkt != 0 && (mrt_api_config & MRT_MFC_RP) && + if (pim_squelch_wholepkt != 0 && (V_mrt_api_config & MRT_MFC_RP) && in_nullhost(rt->mfc_rp)) return 0; @@ -2332,7 +2353,7 @@ pim_register_send(struct ip *ip, struct mm = m_pullup(mm, sizeof(struct ip)); if (mm != NULL) { ip = mtod(mm, struct ip *); - if ((mrt_api_config & MRT_MFC_RP) && !in_nullhost(rt->mfc_rp)) { + if ((V_mrt_api_config & MRT_MFC_RP) && !in_nullhost(rt->mfc_rp)) { pim_register_send_rp(ip, vifp, mm, rt); } else { pim_register_send_upcall(ip, vifp, mm, rt); @@ -2425,7 +2446,7 @@ pim_register_send_upcall(struct ip *ip, im = mtod(mb_first, struct igmpmsg *); im->im_msgtype = IGMPMSG_WHOLEPKT; im->im_mbz = 0; - im->im_vif = vifp - viftable; + im->im_vif = vifp - V_viftable; im->im_src = ip->ip_src; im->im_dst = ip->ip_dst; @@ -2461,7 +2482,7 @@ pim_register_send_rp(struct ip *ip, stru VIF_LOCK_ASSERT(); - if ((vifi >= numvifs) || in_nullhost(viftable[vifi].v_lcl_addr)) { + if ((vifi >= V_numvifs) || in_nullhost(V_viftable[vifi].v_lcl_addr)) { m_freem(mb_copy); return EADDRNOTAVAIL; /* The iif vif is invalid */ } @@ -2487,7 +2508,7 @@ pim_register_send_rp(struct ip *ip, stru *ip_outer = pim_encap_iphdr; ip_outer->ip_id = ip_newid(); ip_outer->ip_len = len + sizeof(pim_encap_iphdr) + sizeof(pim_encap_pimhdr); - ip_outer->ip_src = viftable[vifi].v_lcl_addr; + ip_outer->ip_src = V_viftable[vifi].v_lcl_addr; ip_outer->ip_dst = rt->mfc_rp; /* * Copy the inner header TOS to the outer header, and take care of the @@ -2500,7 +2521,7 @@ pim_register_send_rp(struct ip *ip, stru + sizeof(pim_encap_iphdr)); *pimhdr = pim_encap_pimhdr; /* If the iif crosses a border, set the Border-bit */ - if (rt->mfc_flags[vifi] & MRT_MFC_FLAGS_BORDER_VIF & mrt_api_config) + if (rt->mfc_flags[vifi] & MRT_MFC_FLAGS_BORDER_VIF & V_mrt_api_config) pimhdr->flags |= htonl(PIM_BORDER_REGISTER); mb_first->m_data += sizeof(pim_encap_iphdr); @@ -2637,15 +2658,15 @@ pim_input(struct mbuf *m, int off) struct ifnet *vifp; VIF_LOCK(); - if ((reg_vif_num >= numvifs) || (reg_vif_num == VIFI_INVALID)) { + if ((V_reg_vif_num >= V_numvifs) || (V_reg_vif_num == VIFI_INVALID)) { VIF_UNLOCK(); CTR2(KTR_IPMF, "%s: register vif not set: %d", __func__, - (int)reg_vif_num); + (int)V_reg_vif_num); m_freem(m); return; } /* XXX need refcnt? */ - vifp = viftable[reg_vif_num].v_ifp; + vifp = V_viftable[V_reg_vif_num].v_ifp; VIF_UNLOCK(); *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-stable@FreeBSD.ORG Wed Sep 8 14:22:36 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 18CFD10656A5; Wed, 8 Sep 2010 14:22:36 +0000 (UTC) (envelope-from zec@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id F261A8FC13; Wed, 8 Sep 2010 14:22:35 +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 o88EMZog034506; Wed, 8 Sep 2010 14:22:35 GMT (envelope-from zec@svn.freebsd.org) Received: (from zec@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o88EMZZH034502; Wed, 8 Sep 2010 14:22:35 GMT (envelope-from zec@svn.freebsd.org) Message-Id: <201009081422.o88EMZZH034502@svn.freebsd.org> From: Marko Zec Date: Wed, 8 Sep 2010 14:22:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212320 - stable/8/sys/net X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Sep 2010 14:22:36 -0000 Author: zec Date: Wed Sep 8 14:22:35 2010 New Revision: 212320 URL: http://svn.freebsd.org/changeset/base/212320 Log: MFC r211283: When moving an ethernet ifnet from one vnet to another, destroy the associated ng_ether netgraph node in the current vnet, and create a new one in the target vnet. Reviewed by: julian Modified: stable/8/sys/net/if.c stable/8/sys/net/if_ethersubr.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/net/if.c ============================================================================== --- stable/8/sys/net/if.c Wed Sep 8 14:21:12 2010 (r212319) +++ stable/8/sys/net/if.c Wed Sep 8 14:22:35 2010 (r212320) @@ -974,12 +974,21 @@ if_vmove(struct ifnet *ifp, struct vnet */ IFNET_WLOCK(); ifindex_free_locked(ifp->if_index); + IFNET_WUNLOCK(); + + /* + * Perform interface-specific reassignment tasks, if provided by + * the driver. + */ + if (ifp->if_reassign != NULL) + ifp->if_reassign(ifp, new_vnet, NULL); /* * Switch to the context of the target vnet. */ CURVNET_SET_QUIET(new_vnet); + IFNET_WLOCK(); if (ifindex_alloc_locked(&idx) != 0) { IFNET_WUNLOCK(); panic("if_index overflow"); Modified: stable/8/sys/net/if_ethersubr.c ============================================================================== --- stable/8/sys/net/if_ethersubr.c Wed Sep 8 14:21:12 2010 (r212319) +++ stable/8/sys/net/if_ethersubr.c Wed Sep 8 14:22:35 2010 (r212320) @@ -135,6 +135,9 @@ static const u_char etherbroadcastaddr[E static int ether_resolvemulti(struct ifnet *, struct sockaddr **, struct sockaddr *); +#ifdef VIMAGE +static void ether_reassign(struct ifnet *, struct vnet *, char *); +#endif /* XXX: should be in an arp support file, not here */ MALLOC_DEFINE(M_ARPCOM, "arpcom", "802.* interface internals"); @@ -954,6 +957,9 @@ ether_ifattach(struct ifnet *ifp, const ifp->if_output = ether_output; ifp->if_input = ether_input; ifp->if_resolvemulti = ether_resolvemulti; +#ifdef VIMAGE + ifp->if_reassign = ether_reassign; +#endif if (ifp->if_baudrate == 0) ifp->if_baudrate = IF_Mbps(10); /* just a default */ ifp->if_broadcastaddr = etherbroadcastaddr; @@ -993,6 +999,25 @@ ether_ifdetach(struct ifnet *ifp) if_detach(ifp); } +#ifdef VIMAGE +void +ether_reassign(struct ifnet *ifp, struct vnet *new_vnet, char *unused __unused) +{ + + if (IFP2AC(ifp)->ac_netgraph != NULL) { + KASSERT(ng_ether_detach_p != NULL, + ("ng_ether_detach_p is NULL")); + (*ng_ether_detach_p)(ifp); + } + + if (ng_ether_attach_p != NULL) { + CURVNET_SET_QUIET(new_vnet); + (*ng_ether_attach_p)(ifp); + CURVNET_RESTORE(); + } +} +#endif + SYSCTL_DECL(_net_link); SYSCTL_NODE(_net_link, IFT_ETHER, ether, CTLFLAG_RW, 0, "Ethernet"); #if defined(INET) || defined(INET6) From owner-svn-src-stable@FreeBSD.ORG Wed Sep 8 18:03:40 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A1E9010656C5; Wed, 8 Sep 2010 18:03:40 +0000 (UTC) (envelope-from jh@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 90ABB8FC20; Wed, 8 Sep 2010 18:03:40 +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 o88I3eTW057395; Wed, 8 Sep 2010 18:03:40 GMT (envelope-from jh@svn.freebsd.org) Received: (from jh@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o88I3eJI057392; Wed, 8 Sep 2010 18:03:40 GMT (envelope-from jh@svn.freebsd.org) Message-Id: <201009081803.o88I3eJI057392@svn.freebsd.org> From: Jaakko Heinonen Date: Wed, 8 Sep 2010 18:03:40 +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: r212327 - in stable/7/contrib/nvi: docs ex X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Sep 2010 18:03:40 -0000 Author: jh Date: Wed Sep 8 18:03:40 2010 New Revision: 212327 URL: http://svn.freebsd.org/changeset/base/212327 Log: MFC r208611: Fix misspelling of "substitution". PR: bin/130874 Modified: stable/7/contrib/nvi/docs/help stable/7/contrib/nvi/ex/ex_cmd.c Directory Properties: stable/7/contrib/nvi/ (props changed) Modified: stable/7/contrib/nvi/docs/help ============================================================================== --- stable/7/contrib/nvi/docs/help Wed Sep 8 17:53:34 2010 (r212326) +++ stable/7/contrib/nvi/docs/help Wed Sep 8 18:03:40 2010 (r212327) @@ -129,7 +129,7 @@ EX COMMANDS: ^D: scroll lines !: filter lines through commands or run commands #: display numbered lines - &: repeat the last subsitution + &: repeat the last substitution *: execute a buffer <: shift lines left =: display line number Modified: stable/7/contrib/nvi/ex/ex_cmd.c ============================================================================== --- stable/7/contrib/nvi/ex/ex_cmd.c Wed Sep 8 17:53:34 2010 (r212326) +++ stable/7/contrib/nvi/ex/ex_cmd.c Wed Sep 8 18:03:40 2010 (r212327) @@ -68,7 +68,7 @@ EXCMDLIST const cmds[] = { {"&", ex_subagain, E_ADDR2, "s", "[line [,line]] & [cgr] [count] [#lp]", - "repeat the last subsitution"}, + "repeat the last substitution"}, /* C_STAR */ {"*", ex_at, 0, "b", From owner-svn-src-stable@FreeBSD.ORG Wed Sep 8 18:06:06 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2A07910656DC; Wed, 8 Sep 2010 18:06:06 +0000 (UTC) (envelope-from jh@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 186488FC1E; Wed, 8 Sep 2010 18:06:06 +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 o88I65u8057711; Wed, 8 Sep 2010 18:06:05 GMT (envelope-from jh@svn.freebsd.org) Received: (from jh@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o88I65v5057708; Wed, 8 Sep 2010 18:06:05 GMT (envelope-from jh@svn.freebsd.org) Message-Id: <201009081806.o88I65v5057708@svn.freebsd.org> From: Jaakko Heinonen Date: Wed, 8 Sep 2010 18:06:05 +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: r212328 - stable/7/contrib/nvi/vi X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Sep 2010 18:06:06 -0000 Author: jh Date: Wed Sep 8 18:06:05 2010 New Revision: 212328 URL: http://svn.freebsd.org/changeset/base/212328 Log: MFC r208612: Fixes from NetBSD for nvi visual mode PR: bin/21089, bin/136393 Modified: stable/7/contrib/nvi/vi/v_ex.c stable/7/contrib/nvi/vi/v_txt.c Directory Properties: stable/7/contrib/nvi/ (props changed) Modified: stable/7/contrib/nvi/vi/v_ex.c ============================================================================== --- stable/7/contrib/nvi/vi/v_ex.c Wed Sep 8 18:03:40 2010 (r212327) +++ stable/7/contrib/nvi/vi/v_ex.c Wed Sep 8 18:06:05 2010 (r212328) @@ -428,6 +428,10 @@ v_ex(sp, vp) if (tp->term == TERM_BS) break; + /* If the user changed their mind, return. */ + if (tp->term != TERM_OK) + break; + /* Log the command. */ if (O_STR(sp, O_CEDIT) != NULL && v_ecl_log(sp, tp)) return (1); Modified: stable/7/contrib/nvi/vi/v_txt.c ============================================================================== --- stable/7/contrib/nvi/vi/v_txt.c Wed Sep 8 18:03:40 2010 (r212327) +++ stable/7/contrib/nvi/vi/v_txt.c Wed Sep 8 18:06:05 2010 (r212328) @@ -510,15 +510,6 @@ next: if (v_event_get(sp, evp, 0, ec_fla case E_EOF: F_SET(sp, SC_EXIT_FORCE); return (1); - case E_INTERRUPT: - /* - * !!! - * Historically, exited the user from text input - * mode or cancelled a colon command, and returned to command - * mode. It also beeped the terminal, but that seems a bit - * excessive. - */ - goto k_escape; case E_REPAINT: if (vs_repaint(sp, &ev)) return (1); @@ -526,10 +517,37 @@ next: if (v_event_get(sp, evp, 0, ec_fla case E_WRESIZE: /* interrupts the input mode. */ v_emsg(sp, NULL, VIM_WRESIZE); - goto k_escape; + /* FALLTHROUGH */ default: - v_event_err(sp, evp); - goto k_escape; + if (evp->e_event != E_INTERRUPT && evp->e_event != E_WRESIZE) + v_event_err(sp, evp); + /* + * !!! + * Historically, exited the user from text input + * mode or cancelled a colon command, and returned to command + * mode. It also beeped the terminal, but that seems a bit + * excessive. + */ + /* + * If we are recording, morph into key so that + * we can repeat the command safely: there is no way to + * invalidate the repetition of an instance of a command, + * which would be the alternative possibility. + * If we are not recording (most likely on the command line), + * simply discard the input and return to command mode + * so that an INTERRUPT doesn't become for example a file + * completion request. -aymeric + */ + if (LF_ISSET(TXT_RECORD)) { + evp->e_event = E_CHARACTER; + evp->e_c = 033; + evp->e_flags = 0; + evp->e_value = K_ESCAPE; + break; + } else { + tp->term = TERM_ESC; + goto k_escape; + } } /* @@ -539,7 +557,7 @@ next: if (v_event_get(sp, evp, 0, ec_fla * This was not documented as far as I know, and is a great test of vi * clones. */ - if (rcol == 0 && !LF_ISSET(TXT_REPLAY) && evp->e_c == '\0') { + if (LF_ISSET(TXT_RECORD) && rcol == 0 && evp->e_c == '\0') { if (vip->rep == NULL) goto done; @@ -1456,6 +1474,7 @@ done: /* Leave input mode. */ err: alloc_err: + F_CLR(sp, SC_TINPUT); txt_err(sp, &sp->tiq); return (1); } @@ -2216,8 +2235,8 @@ txt_fc_col(sp, argc, argv) /* If the largest file name is too large, just print them. */ if (colwidth > sp->cols) { - p = msg_print(sp, av[0]->bp + prefix, &nf); for (ac = argc, av = argv; ac > 0; --ac, ++av) { + p = msg_print(sp, av[0]->bp + prefix, &nf); (void)ex_printf(sp, "%s\n", p); if (F_ISSET(gp, G_INTERRUPTED)) break; From owner-svn-src-stable@FreeBSD.ORG Thu Sep 9 06:43:18 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BDBA510656DA; Thu, 9 Sep 2010 06:43:18 +0000 (UTC) (envelope-from bz@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id AC2138FC16; Thu, 9 Sep 2010 06:43:18 +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 o896hIet043233; Thu, 9 Sep 2010 06:43:18 GMT (envelope-from bz@svn.freebsd.org) Received: (from bz@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o896hI80043228; Thu, 9 Sep 2010 06:43:18 GMT (envelope-from bz@svn.freebsd.org) Message-Id: <201009090643.o896hI80043228@svn.freebsd.org> From: "Bjoern A. Zeeb" Date: Thu, 9 Sep 2010 06:43:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212351 - in stable/8/sys: netinet netinet6 X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Sep 2010 06:43:18 -0000 Author: bz Date: Thu Sep 9 06:43:18 2010 New Revision: 212351 URL: http://svn.freebsd.org/changeset/base/212351 Log: MFC r212155: MFp4 CH=183052 183053 183258: In protosw we define pr_protocol as short, while on the wire it is an uint8_t. That way we can have "internal" protocols like DIVERT, SEND or gaps for modules (PROTO_SPACER). Switch ipproto_{un,}register to accept a short protocol number(*) and do an upfront check for valid boundries. With this we also consistently report EPROTONOSUPPORT for out of bounds protocols, as we did for proto == 0. This allows a caller to not error for this case, which is especially important if we want to automatically call these from domain handling. (*) the functions have been without any in-tree consumer since the initial introducation, so this is considered save. Implement ip6proto_{un,}register() similarly to their legacy IP counter parts to allow modules to hook up dynamically. Reviewed by: philip, will Modified: stable/8/sys/netinet/ip_input.c stable/8/sys/netinet/ip_var.h stable/8/sys/netinet6/ip6_input.c stable/8/sys/netinet6/ip6_var.h Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/netinet/ip_input.c ============================================================================== --- stable/8/sys/netinet/ip_input.c Thu Sep 9 03:33:07 2010 (r212350) +++ stable/8/sys/netinet/ip_input.c Thu Sep 9 06:43:18 2010 (r212351) @@ -1293,12 +1293,12 @@ ip_drain(void) * in inetsw[], either statically or through pf_proto_register(). */ int -ipproto_register(u_char ipproto) +ipproto_register(short ipproto) { struct protosw *pr; /* Sanity checks. */ - if (ipproto == 0) + if (ipproto <= 0 || ipproto >= IPPROTO_MAX) return (EPROTONOSUPPORT); /* @@ -1316,24 +1316,20 @@ ipproto_register(u_char ipproto) pr < inetdomain.dom_protoswNPROTOSW; pr++) { if (pr->pr_domain->dom_family == PF_INET && pr->pr_protocol && pr->pr_protocol == ipproto) { - /* Be careful to only index valid IP protocols. */ - if (pr->pr_protocol < IPPROTO_MAX) { - ip_protox[pr->pr_protocol] = pr - inetsw; - return (0); - } else - return (EINVAL); + ip_protox[pr->pr_protocol] = pr - inetsw; + return (0); } } return (EPROTONOSUPPORT); } int -ipproto_unregister(u_char ipproto) +ipproto_unregister(short ipproto) { struct protosw *pr; /* Sanity checks. */ - if (ipproto == 0) + if (ipproto <= 0 || ipproto >= IPPROTO_MAX) return (EPROTONOSUPPORT); /* Check if the protocol was indeed registered. */ Modified: stable/8/sys/netinet/ip_var.h ============================================================================== --- stable/8/sys/netinet/ip_var.h Thu Sep 9 03:33:07 2010 (r212350) +++ stable/8/sys/netinet/ip_var.h Thu Sep 9 06:43:18 2010 (r212351) @@ -220,8 +220,8 @@ extern int int ip_output(struct mbuf *, struct mbuf *, struct route *, int, struct ip_moptions *, struct inpcb *); -int ipproto_register(u_char); -int ipproto_unregister(u_char); +int ipproto_register(short); +int ipproto_unregister(short); struct mbuf * ip_reass(struct mbuf *); struct in_ifaddr * Modified: stable/8/sys/netinet6/ip6_input.c ============================================================================== --- stable/8/sys/netinet6/ip6_input.c Thu Sep 9 03:33:07 2010 (r212350) +++ stable/8/sys/netinet6/ip6_input.c Thu Sep 9 06:43:18 2010 (r212351) @@ -202,6 +202,64 @@ ip6_init(void) netisr_register(&ip6_nh); } +/* + * The protocol to be inserted into ip6_protox[] must be already registered + * in inet6sw[], either statically or through pf_proto_register(). + */ +int +ip6proto_register(short ip6proto) +{ + struct ip6protosw *pr; + + /* Sanity checks. */ + if (ip6proto <= 0 || ip6proto >= IPPROTO_MAX) + return (EPROTONOSUPPORT); + + /* + * The protocol slot must not be occupied by another protocol + * already. An index pointing to IPPROTO_RAW is unused. + */ + pr = (struct ip6protosw *)pffindproto(PF_INET6, IPPROTO_RAW, SOCK_RAW); + if (pr == NULL) + return (EPFNOSUPPORT); + if (ip6_protox[ip6proto] != pr - inet6sw) /* IPPROTO_RAW */ + return (EEXIST); + + /* + * Find the protocol position in inet6sw[] and set the index. + */ + for (pr = (struct ip6protosw *)inet6domain.dom_protosw; + pr < (struct ip6protosw *)inet6domain.dom_protoswNPROTOSW; pr++) { + if (pr->pr_domain->dom_family == PF_INET6 && + pr->pr_protocol && pr->pr_protocol == ip6proto) { + ip6_protox[pr->pr_protocol] = pr - inet6sw; + return (0); + } + } + return (EPROTONOSUPPORT); +} + +int +ip6proto_unregister(short ip6proto) +{ + struct ip6protosw *pr; + + /* Sanity checks. */ + if (ip6proto <= 0 || ip6proto >= IPPROTO_MAX) + return (EPROTONOSUPPORT); + + /* Check if the protocol was indeed registered. */ + pr = (struct ip6protosw *)pffindproto(PF_INET6, IPPROTO_RAW, SOCK_RAW); + if (pr == NULL) + return (EPFNOSUPPORT); + if (ip6_protox[ip6proto] == pr - inet6sw) /* IPPROTO_RAW */ + return (ENOENT); + + /* Reset the protocol slot to IPPROTO_RAW. */ + ip6_protox[ip6proto] = pr - inet6sw; + return (0); +} + #ifdef VIMAGE void ip6_destroy() Modified: stable/8/sys/netinet6/ip6_var.h ============================================================================== --- stable/8/sys/netinet6/ip6_var.h Thu Sep 9 03:33:07 2010 (r212350) +++ stable/8/sys/netinet6/ip6_var.h Thu Sep 9 06:43:18 2010 (r212351) @@ -368,6 +368,9 @@ void ip6_init __P((void)); #ifdef VIMAGE void ip6_destroy __P((void)); #endif +int ip6proto_register(short); +int ip6proto_unregister(short); + void ip6_input __P((struct mbuf *)); struct in6_ifaddr *ip6_getdstifaddr __P((struct mbuf *)); void ip6_freepcbopts __P((struct ip6_pktopts *)); From owner-svn-src-stable@FreeBSD.ORG Thu Sep 9 06:44:22 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C398C10656CB; Thu, 9 Sep 2010 06:44:22 +0000 (UTC) (envelope-from bz@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id B23C68FC08; Thu, 9 Sep 2010 06:44:22 +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 o896iMch043561; Thu, 9 Sep 2010 06:44:22 GMT (envelope-from bz@svn.freebsd.org) Received: (from bz@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o896iMoC043556; Thu, 9 Sep 2010 06:44:22 GMT (envelope-from bz@svn.freebsd.org) Message-Id: <201009090644.o896iMoC043556@svn.freebsd.org> From: "Bjoern A. Zeeb" Date: Thu, 9 Sep 2010 06:44:22 +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: r212352 - in stable/7/sys: netinet netinet6 X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Sep 2010 06:44:22 -0000 Author: bz Date: Thu Sep 9 06:44:22 2010 New Revision: 212352 URL: http://svn.freebsd.org/changeset/base/212352 Log: MFC r212155: MFp4 CH=183052 183053 183258: In protosw we define pr_protocol as short, while on the wire it is an uint8_t. That way we can have "internal" protocols like DIVERT, SEND or gaps for modules (PROTO_SPACER). Switch ipproto_{un,}register to accept a short protocol number(*) and do an upfront check for valid boundries. With this we also consistently report EPROTONOSUPPORT for out of bounds protocols, as we did for proto == 0. This allows a caller to not error for this case, which is especially important if we want to automatically call these from domain handling. (*) the functions have been without any in-tree consumer since the initial introducation, so this is considered save. Implement ip6proto_{un,}register() similarly to their legacy IP counter parts to allow modules to hook up dynamically. Reviewed by: philip, will Modified: stable/7/sys/netinet/ip_input.c stable/7/sys/netinet/ip_var.h stable/7/sys/netinet6/ip6_input.c stable/7/sys/netinet6/ip6_var.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/netinet/ip_input.c ============================================================================== --- stable/7/sys/netinet/ip_input.c Thu Sep 9 06:43:18 2010 (r212351) +++ stable/7/sys/netinet/ip_input.c Thu Sep 9 06:44:22 2010 (r212352) @@ -1137,12 +1137,12 @@ ip_drain(void) * in inetsw[], either statically or through pf_proto_register(). */ int -ipproto_register(u_char ipproto) +ipproto_register(short ipproto) { struct protosw *pr; /* Sanity checks. */ - if (ipproto == 0) + if (ipproto <= 0 || ipproto >= IPPROTO_MAX) return (EPROTONOSUPPORT); /* @@ -1160,24 +1160,20 @@ ipproto_register(u_char ipproto) pr < inetdomain.dom_protoswNPROTOSW; pr++) { if (pr->pr_domain->dom_family == PF_INET && pr->pr_protocol && pr->pr_protocol == ipproto) { - /* Be careful to only index valid IP protocols. */ - if (pr->pr_protocol < IPPROTO_MAX) { - ip_protox[pr->pr_protocol] = pr - inetsw; - return (0); - } else - return (EINVAL); + ip_protox[pr->pr_protocol] = pr - inetsw; + return (0); } } return (EPROTONOSUPPORT); } int -ipproto_unregister(u_char ipproto) +ipproto_unregister(short ipproto) { struct protosw *pr; /* Sanity checks. */ - if (ipproto == 0) + if (ipproto <= 0 || ipproto >= IPPROTO_MAX) return (EPROTONOSUPPORT); /* Check if the protocol was indeed registered. */ Modified: stable/7/sys/netinet/ip_var.h ============================================================================== --- stable/7/sys/netinet/ip_var.h Thu Sep 9 06:43:18 2010 (r212351) +++ stable/7/sys/netinet/ip_var.h Thu Sep 9 06:44:22 2010 (r212352) @@ -204,8 +204,8 @@ extern int int ip_output(struct mbuf *, struct mbuf *, struct route *, int, struct ip_moptions *, struct inpcb *); -int ipproto_register(u_char); -int ipproto_unregister(u_char); +int ipproto_register(short); +int ipproto_unregister(short); struct mbuf * ip_reass(struct mbuf *); struct in_ifaddr * Modified: stable/7/sys/netinet6/ip6_input.c ============================================================================== --- stable/7/sys/netinet6/ip6_input.c Thu Sep 9 06:43:18 2010 (r212351) +++ stable/7/sys/netinet6/ip6_input.c Thu Sep 9 06:44:22 2010 (r212352) @@ -182,6 +182,64 @@ ip6_init(void) ip6_desync_factor = arc4random() % MAX_TEMP_DESYNC_FACTOR; } +/* + * The protocol to be inserted into ip6_protox[] must be already registered + * in inet6sw[], either statically or through pf_proto_register(). + */ +int +ip6proto_register(short ip6proto) +{ + struct ip6protosw *pr; + + /* Sanity checks. */ + if (ip6proto <= 0 || ip6proto >= IPPROTO_MAX) + return (EPROTONOSUPPORT); + + /* + * The protocol slot must not be occupied by another protocol + * already. An index pointing to IPPROTO_RAW is unused. + */ + pr = (struct ip6protosw *)pffindproto(PF_INET6, IPPROTO_RAW, SOCK_RAW); + if (pr == NULL) + return (EPFNOSUPPORT); + if (ip6_protox[ip6proto] != pr - inet6sw) /* IPPROTO_RAW */ + return (EEXIST); + + /* + * Find the protocol position in inet6sw[] and set the index. + */ + for (pr = (struct ip6protosw *)inet6domain.dom_protosw; + pr < (struct ip6protosw *)inet6domain.dom_protoswNPROTOSW; pr++) { + if (pr->pr_domain->dom_family == PF_INET6 && + pr->pr_protocol && pr->pr_protocol == ip6proto) { + ip6_protox[pr->pr_protocol] = pr - inet6sw; + return (0); + } + } + return (EPROTONOSUPPORT); +} + +int +ip6proto_unregister(short ip6proto) +{ + struct ip6protosw *pr; + + /* Sanity checks. */ + if (ip6proto <= 0 || ip6proto >= IPPROTO_MAX) + return (EPROTONOSUPPORT); + + /* Check if the protocol was indeed registered. */ + pr = (struct ip6protosw *)pffindproto(PF_INET6, IPPROTO_RAW, SOCK_RAW); + if (pr == NULL) + return (EPFNOSUPPORT); + if (ip6_protox[ip6proto] == pr - inet6sw) /* IPPROTO_RAW */ + return (ENOENT); + + /* Reset the protocol slot to IPPROTO_RAW. */ + ip6_protox[ip6proto] = pr - inet6sw; + return (0); +} + static void ip6_init2(void *dummy) { Modified: stable/7/sys/netinet6/ip6_var.h ============================================================================== --- stable/7/sys/netinet6/ip6_var.h Thu Sep 9 06:43:18 2010 (r212351) +++ stable/7/sys/netinet6/ip6_var.h Thu Sep 9 06:44:22 2010 (r212352) @@ -329,6 +329,9 @@ int icmp6_ctloutput __P((struct socket * struct in6_ifaddr; void ip6_init __P((void)); +int ip6proto_register(short); +int ip6proto_unregister(short); + void ip6_input __P((struct mbuf *)); struct in6_ifaddr *ip6_getdstifaddr __P((struct mbuf *)); void ip6_freepcbopts __P((struct ip6_pktopts *)); From owner-svn-src-stable@FreeBSD.ORG Thu Sep 9 21:26:56 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0ACF710656CE; Thu, 9 Sep 2010 21:26:56 +0000 (UTC) (envelope-from brueffer@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id ED7468FC19; Thu, 9 Sep 2010 21:26:55 +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 o89LQt0X034785; Thu, 9 Sep 2010 21:26:55 GMT (envelope-from brueffer@svn.freebsd.org) Received: (from brueffer@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o89LQt4p034783; Thu, 9 Sep 2010 21:26:55 GMT (envelope-from brueffer@svn.freebsd.org) Message-Id: <201009092126.o89LQt4p034783@svn.freebsd.org> From: Christian Brueffer Date: Thu, 9 Sep 2010 21:26:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212386 - stable/8/sys/modules X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Sep 2010 21:26:56 -0000 Author: brueffer Date: Thu Sep 9 21:26:55 2010 New Revision: 212386 URL: http://svn.freebsd.org/changeset/base/212386 Log: MFC: r207979 Build the ixgbe(4) and mwlfw(4) modules by default. Modified: stable/8/sys/modules/Makefile Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/modules/Makefile ============================================================================== --- stable/8/sys/modules/Makefile Thu Sep 9 21:20:18 2010 (r212385) +++ stable/8/sys/modules/Makefile Thu Sep 9 21:26:55 2010 (r212386) @@ -144,6 +144,7 @@ SUBDIR= ${_3dfx} \ ${_iwn} \ ${_iwnfw} \ ${_ixgb} \ + ${_ixgbe} \ jme \ joy \ kbdmux \ @@ -190,6 +191,7 @@ SUBDIR= ${_3dfx} \ msk \ mvs \ mwl \ + mwlfw \ mxge \ my \ ${_ncp} \ @@ -457,6 +459,7 @@ _iwifw= iwifw _iwn= iwn _iwnfw= iwnfw _ixgb= ixgb +_ixgbe= ixgbe _mly= mly _nfe= nfe _nve= nve @@ -527,6 +530,7 @@ _iwifw= iwifw _iwn= iwn _iwnfw= iwnfw _ixgb= ixgb +_ixgbe= ixgbe _lindev= lindev _linprocfs= linprocfs _linsysfs= linsysfs From owner-svn-src-stable@FreeBSD.ORG Fri Sep 10 03:52:05 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D4F70106564A; Fri, 10 Sep 2010 03:52:05 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id C36D28FC1B; Fri, 10 Sep 2010 03:52:05 +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 o8A3q52b073129; Fri, 10 Sep 2010 03:52:05 GMT (envelope-from imp@svn.freebsd.org) Received: (from imp@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o8A3q5u4073127; Fri, 10 Sep 2010 03:52:05 GMT (envelope-from imp@svn.freebsd.org) Message-Id: <201009100352.o8A3q5u4073127@svn.freebsd.org> From: Warner Losh Date: Fri, 10 Sep 2010 03:52:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212406 - stable/8/tools/tools/nanobsd X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Sep 2010 03:52:05 -0000 Author: imp Date: Fri Sep 10 03:52:05 2010 New Revision: 212406 URL: http://svn.freebsd.org/changeset/base/212406 Log: MFC: r212169: Allow / in the NANO_DEVICE r209225: Allow boot.config to have different values than just -h. r209210: Allow population of /cfg and /data. Begin the move to making all slice creation overrideable too, but there's a few problems doing that for the duplicated partitions (s1 and s2), so just comment that it needs work. r209209: Create a make.conf. not needed for runtime, but some ports want to spam it at compile or install time. r209207: make these convenience functions more convenient by accepting all args, not just the first. makes mechanical conversion of old style more forgiving. r207436: Fix typo in usage message. Add -n to the list of valid arguments. r206276: Fix comment about NANO_ARCH. It can be set now. Also add a warning about how it confuses TARGET and TARGET_ARCH and the need to separate the two out into independent variables. Modified: stable/8/tools/tools/nanobsd/nanobsd.sh Directory Properties: stable/8/tools/tools/nanobsd/ (props changed) Modified: stable/8/tools/tools/nanobsd/nanobsd.sh ============================================================================== --- stable/8/tools/tools/nanobsd/nanobsd.sh Fri Sep 10 01:47:37 2010 (r212405) +++ stable/8/tools/tools/nanobsd/nanobsd.sh Fri Sep 10 03:52:05 2010 (r212406) @@ -124,6 +124,10 @@ NANO_HEADS=16 NANO_BOOT0CFG="-o packet -s 1 -m 3" NANO_BOOTLOADER="boot/boot0sio" +# boot2 flags/options +# default force serial console +NANO_BOOT2CFG="-h" + # Backing type of md(4) device # Can be "file" or "swap" NANO_MD_BACKING="file" @@ -132,7 +136,10 @@ NANO_MD_BACKING="file" PPLEVEL=3 ####################################################################### -# Not a variable at this time +# Architecture to build. Corresponds to TARGET_ARCH in a buildworld. +# Unfortunately, there's no way to set TARGET at this time, and it +# conflates the two, so architectures where TARGET != TARGET_ARCH do +# not work. This defaults to the arch of the current machine. NANO_ARCH=`uname -p` @@ -354,6 +361,30 @@ prune_usr() ( done ) +populate_slice ( ) ( + local dev dir mnt + dev=$1 + dir=$2 + mnt=$3 + test -z $2 && dir=/var/empty + test -d $d || dir=/var/empty + echo "Creating ${dev} with ${dir} (mounting on ${mnt})" + newfs ${NANO_NEWFS} ${dev} + mount ${dev} ${mnt} + cd ${dir} + find . -print | grep -Ev '/(CVS|\.svn)' | cpio -dumpv ${mnt} + df -i ${mnt} + umount ${mnt} +) + +populate_cfg_slice ( ) ( + populate_slice "$1" "$2" "$3" +) + +populate_data_slice ( ) ( + populate_slice "$1" "$2" "$3" +) + create_i386_diskimage ( ) ( pprint 2 "build diskimage" pprint 3 "log: ${NANO_OBJ}/_.di" @@ -453,6 +484,7 @@ create_i386_diskimage ( ) ( bsdlabel ${MD}s1 # Create first image + # XXX: should use populate_slice for easier override newfs ${NANO_NEWFS} /dev/${MD}s1a mount /dev/${MD}s1a ${MNT} df -i ${MNT} @@ -471,19 +503,17 @@ create_i386_diskimage ( ) ( mount /dev/${MD}s2a ${MNT} for f in ${MNT}/etc/fstab ${MNT}/conf/base/etc/fstab do - sed -i "" "s/${NANO_DRIVE}s1/${NANO_DRIVE}s2/g" $f + sed -i "" "s=${NANO_DRIVE}s1=${NANO_DRIVE}s2=g" $f done umount ${MNT} fi # Create Config slice - newfs ${NANO_NEWFS} /dev/${MD}s3 - # XXX: fill from where ? + populate_cfg_slice /dev/${MD}s3 "${NANO_CFGDIR}" ${MNT} # Create Data slice, if any. if [ $NANO_DATASIZE -ne 0 ] ; then - newfs ${NANO_NEWFS} /dev/${MD}s4 - # XXX: fill from where ? + populate_data_slice /dev/${MD}s4 "${NANO_DATADIR}" ${MNT} fi if [ "${NANO_MD_BACKING}" = "swap" ] ; then @@ -582,7 +612,7 @@ cust_comconsole () ( sed -i "" -e '/^ttyv[0-8]/s/ on/ off/' ${NANO_WORLDDIR}/etc/ttys # Tell loader to use serial console early. - echo " -h" > ${NANO_WORLDDIR}/boot.config + echo "${NANO_BOOT2CFG}" > ${NANO_WORLDDIR}/boot.config ) ####################################################################### @@ -650,19 +680,19 @@ cust_pkg () ( ####################################################################### # Convenience function: -# Register $1 as customize function. +# Register all args as customize function. customize_cmd () { - NANO_CUSTOMIZE="$NANO_CUSTOMIZE $1" + NANO_CUSTOMIZE="$NANO_CUSTOMIZE $*" } ####################################################################### # Convenience function: -# Register $1 as late customize function to run just before +# Register all args as late customize function to run just before # image creation. late_customize_cmd () { - NANO_LATE_CUSTOMIZE="$NANO_LATE_CUSTOMIZE $1" + NANO_LATE_CUSTOMIZE="$NANO_LATE_CUSTOMIZE $*" } ####################################################################### @@ -682,12 +712,12 @@ pprint() { usage () { ( - echo "Usage: $0 [-bikqvw] [-c config_file]" + echo "Usage: $0 [-biknqvw] [-c config_file]" echo " -b suppress builds (both kernel and world)" echo " -i suppress disk image build" echo " -k suppress buildkernel" echo " -n add -DNO_CLEAN to buildworld, buildkernel, etc" - echo " -q make output more quite" + echo " -q make output more quiet" echo " -v make output more verbose" echo " -w suppress buildworld" echo " -c specify config file" From owner-svn-src-stable@FreeBSD.ORG Fri Sep 10 12:55:36 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 903D8106566C; Fri, 10 Sep 2010 12:55:36 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 64EA98FC13; Fri, 10 Sep 2010 12:55:36 +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 o8ACtamL044121; Fri, 10 Sep 2010 12:55:36 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o8ACtaUU044119; Fri, 10 Sep 2010 12:55:36 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201009101255.o8ACtaUU044119@svn.freebsd.org> From: Konstantin Belousov Date: Fri, 10 Sep 2010 12:55:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212415 - stable/8/sys/kern X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Sep 2010 12:55:36 -0000 Author: kib Date: Fri Sep 10 12:55:36 2010 New Revision: 212415 URL: http://svn.freebsd.org/changeset/base/212415 Log: MFC r211941: Recalcule the return value in pollout(). PR: kern/143029 Tested by: John Plevyak Modified: stable/8/sys/kern/sys_generic.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/kern/sys_generic.c ============================================================================== --- stable/8/sys/kern/sys_generic.c Fri Sep 10 12:16:24 2010 (r212414) +++ stable/8/sys/kern/sys_generic.c Fri Sep 10 12:55:36 2010 (r212415) @@ -76,7 +76,8 @@ static MALLOC_DEFINE(M_IOCTLOPS, "ioctlo static MALLOC_DEFINE(M_SELECT, "select", "select() buffer"); MALLOC_DEFINE(M_IOV, "iov", "large iov's"); -static int pollout(struct pollfd *, struct pollfd *, u_int); +static int pollout(struct thread *, struct pollfd *, struct pollfd *, + u_int); static int pollscan(struct thread *, struct pollfd *, u_int); static int pollrescan(struct thread *); static int selscan(struct thread *, fd_mask **, fd_mask **, int); @@ -1207,7 +1208,7 @@ done: if (error == EWOULDBLOCK) error = 0; if (error == 0) { - error = pollout(bits, uap->fds, nfds); + error = pollout(td, bits, uap->fds, nfds); if (error) goto out; } @@ -1262,22 +1263,27 @@ pollrescan(struct thread *td) static int -pollout(fds, ufds, nfd) +pollout(td, fds, ufds, nfd) + struct thread *td; struct pollfd *fds; struct pollfd *ufds; u_int nfd; { int error = 0; u_int i = 0; + u_int n = 0; for (i = 0; i < nfd; i++) { error = copyout(&fds->revents, &ufds->revents, sizeof(ufds->revents)); if (error) return (error); + if (fds->revents != 0) + n++; fds++; ufds++; } + td->td_retval[0] = n; return (0); } From owner-svn-src-stable@FreeBSD.ORG Fri Sep 10 15:33:26 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id F1B861065675; Fri, 10 Sep 2010 15:33:26 +0000 (UTC) (envelope-from nwhitehorn@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id E17778FC18; Fri, 10 Sep 2010 15:33:26 +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 o8AFXQSR056987; Fri, 10 Sep 2010 15:33:26 GMT (envelope-from nwhitehorn@svn.freebsd.org) Received: (from nwhitehorn@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o8AFXQXW056985; Fri, 10 Sep 2010 15:33:26 GMT (envelope-from nwhitehorn@svn.freebsd.org) Message-Id: <201009101533.o8AFXQXW056985@svn.freebsd.org> From: Nathan Whitehorn Date: Fri, 10 Sep 2010 15:33:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212421 - stable/8/sys/powerpc/aim X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Sep 2010 15:33:27 -0000 Author: nwhitehorn Date: Fri Sep 10 15:33:26 2010 New Revision: 212421 URL: http://svn.freebsd.org/changeset/base/212421 Log: MFC r211861: pmap_mapdev() does not appear to actually need GIANT to be held here, and asserting that is held breaks drm. Modified: stable/8/sys/powerpc/aim/mmu_oea.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/powerpc/aim/mmu_oea.c ============================================================================== --- stable/8/sys/powerpc/aim/mmu_oea.c Fri Sep 10 15:03:56 2010 (r212420) +++ stable/8/sys/powerpc/aim/mmu_oea.c Fri Sep 10 15:33:26 2010 (r212421) @@ -2382,8 +2382,6 @@ moea_mapdev(mmu_t mmu, vm_offset_t pa, v offset = pa & PAGE_MASK; size = roundup(offset + size, PAGE_SIZE); - GIANT_REQUIRED; - /* * If the physical address lies within a valid BAT table entry, * return the 1:1 mapping. This currently doesn't work From owner-svn-src-stable@FreeBSD.ORG Fri Sep 10 17:26:42 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 50039106566B; Fri, 10 Sep 2010 17:26:42 +0000 (UTC) (envelope-from mdf@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 3D34A8FC0C; Fri, 10 Sep 2010 17:26:42 +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 o8AHQgJ1070377; Fri, 10 Sep 2010 17:26:42 GMT (envelope-from mdf@svn.freebsd.org) Received: (from mdf@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o8AHQg8w070370; Fri, 10 Sep 2010 17:26:42 GMT (envelope-from mdf@svn.freebsd.org) Message-Id: <201009101726.o8AHQg8w070370@svn.freebsd.org> From: Matthew D Fleming Date: Fri, 10 Sep 2010 17:26:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212427 - in stable/8: share/man/man9 sys/kern sys/vm X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Sep 2010 17:26:42 -0000 Author: mdf Date: Fri Sep 10 17:26:41 2010 New Revision: 212427 URL: http://svn.freebsd.org/changeset/base/212427 Log: MFC r211194, r211229, r212058, r212063: memguard(9) rewrite r211194: Rework memguard(9) to reserve significantly more KVA to detect use-after-free over a longer time. Also release the backing pages of a guarded allocation at free(9) time to reduce the overhead of using memguard(9). Allow setting and varying the malloc type at run-time. Add knobs to allow: - randomly guarding memory - adding un-backed KVA guard pages to detect underflow and overflow - a lower limit on the size of allocations that are guarded r211229: Fix compile. It seemed better to have memguard.c include opt_vm.h in case future compile-time knobs were added that it wants to use. Also add include guards and forward declarations to vm/memguard.h. r212058: The realloc case for memguard(9) will copy too many bytes when reallocating to a smaller-sized allocation. Fix this issue. r212063: Have memguard(9) crash with an easier-to-debug message on double-free. Modified: stable/8/share/man/man9/memguard.9 stable/8/sys/kern/kern_malloc.c stable/8/sys/vm/memguard.c stable/8/sys/vm/memguard.h stable/8/sys/vm/vm_extern.h stable/8/sys/vm/vm_kern.c Directory Properties: stable/8/share/man/ (props changed) stable/8/share/man/man1/ (props changed) stable/8/share/man/man3/ (props changed) stable/8/share/man/man4/ (props changed) stable/8/share/man/man5/ (props changed) stable/8/share/man/man7/ (props changed) stable/8/share/man/man8/ (props changed) stable/8/share/man/man9/ (props changed) stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/share/man/man9/memguard.9 ============================================================================== --- stable/8/share/man/man9/memguard.9 Fri Sep 10 17:00:48 2010 (r212426) +++ stable/8/share/man/man9/memguard.9 Fri Sep 10 17:26:41 2010 (r212427) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd January 31, 2006 +.Dd August 2, 2010 .Dt MEMGUARD 9 .Os .Sh NAME @@ -41,54 +41,107 @@ multithreaded kernels where race conditi .Pp Currently, .Nm -can only take over +can take over .Fn malloc , .Fn realloc and .Fn free -for a particular malloc type. +for a single malloc type. +.Nm +can also guard all allocations larger than +.Dv PAGE_SIZE , +and can guard a random fraction of all allocations. +There is also a knob to prevent allocations smaller than a specified +size from being guarded, to limit memory waste. .Sh EXAMPLES To use .Nm -for memory type compiled into the kernel, one has to add the -following line to the +for a memory type, either add an entry to .Pa /boot/loader.conf : .Bd -literal -offset indent vm.memguard.desc= .Ed .Pp -Where -.Ar memory_type -is a short description of memory type to monitor. -The short description of memory type is the second argument to -.Xr MALLOC_DEFINE 9 , -so one has to find it in the kernel source. -.Pp -To use -.Nm -for memory type defined in a kernel module, one has to set +Or set the .Va vm.memguard.desc .Xr sysctl 8 -variable before loading the module: +variable at run-time: .Bd -literal -offset indent sysctl vm.memguard.desc= .Ed .Pp +Where +.Ar memory_type +is a short description of the memory type to monitor. +Only allocations from that +.Ar memory_type +made after +.Va vm.memguard.desc +is set will potentially be guarded. +If +.Va vm.memguard.desc +is modified at run-time then only allocations of the new +.Ar memory_type +will potentially be guarded once the +.Xr sysctl 8 +is set. +Existing guarded allocations will still be properly released by +.Xr free 9 . +.Pp +The short description of a +.Xr malloc 9 +type is the second argument to +.Xr MALLOC_DEFINE 9 , +so one has to find it in the kernel source. +.Pp The .Va vm.memguard.divisor -boot-time tunable is used to scale how much of -.Va kmem_map -one wants to allocate for -.Nm . -The default is 10, so -.Va kmem_size Ns /10 -bytes will be used. -The -.Va kmem_size -value can be obtained via the -.Va vm.kmem_size -.Xr sysctl 8 -variable. +boot-time tunable is used to scale how much of the system's physical +memory +.Nm +is allowed to consume. +The default is 10, so up to +.Va cnt.v_page_count Ns /10 +pages can be used. +.Nm +will reserve +.Va vm_kmem_max +/ +.Va vm.memguard.divisor +bytes of virtual address space, limited by twice the physical memory +size. +The physical limit is reported as +.Va vm.memguard.phys_limit +and the virtual space reserved for +.Nm +is reported as +.Va vm.memguard.mapsize . +.Pp +.Nm +will not do page promotions for any allocation smaller than +.Va vm.memguard.minsize +bytes. +The default is 0, meaning all allocations can potentially be guarded. +.Nm +can guard sufficiently large allocations randomly, with average +frequency of every one in 100000 / +.Va vm.memguard.frequency +allocations. +The default is 0, meaning no allocations are randomly guarded. +.Pp +.Nm +can optionally add unmapped guard pages around each allocation to +detect overflow and underflow, if +.Va vm.memguard.options +has the 1 bit set. +This option is enabled by default. +.Nm +will optionally guard all allocations of +.Dv PAGE_SIZE +or larger if +.Va vm.memguard.options +has the 2 bit set. +This option is off by default. .Sh SEE ALSO .Xr sysctl 8 , .Xr vmstat 8 , @@ -102,10 +155,13 @@ first appeared in .Sh AUTHORS .An -nosplit .Nm -was written by +was originally written by .An Bosko Milekic Aq bmilekic@FreeBSD.org . -This manual page was written by +This manual page was originally written by .An Christian Brueffer Aq brueffer@FreeBSD.org . +Additions have been made by +.An Matthew Fleming Aq mdf@FreeBSD.org +to both the implementation and the documentation. .Sh BUGS Currently, it is not possible to override UMA .Xr zone 9 Modified: stable/8/sys/kern/kern_malloc.c ============================================================================== --- stable/8/sys/kern/kern_malloc.c Fri Sep 10 17:00:48 2010 (r212426) +++ stable/8/sys/kern/kern_malloc.c Fri Sep 10 17:26:41 2010 (r212427) @@ -365,8 +365,12 @@ malloc(unsigned long size, struct malloc ("malloc(M_WAITOK) in interrupt context")); #ifdef DEBUG_MEMGUARD - if (memguard_cmp(mtp)) - return memguard_alloc(size, flags); + if (memguard_cmp(mtp, size)) { + va = memguard_alloc(size, flags); + if (va != NULL) + return (va); + /* This is unfortunate but should not be fatal. */ + } #endif #ifdef DEBUG_REDZONE @@ -427,7 +431,7 @@ free(void *addr, struct malloc_type *mtp return; #ifdef DEBUG_MEMGUARD - if (memguard_cmp(mtp)) { + if (is_memguard_addr(addr)) { memguard_free(addr); return; } @@ -496,10 +500,8 @@ realloc(void *addr, unsigned long size, */ #ifdef DEBUG_MEMGUARD -if (memguard_cmp(mtp)) { - slab = NULL; - alloc = size; -} else { + if (is_memguard_addr(addr)) + return (memguard_realloc(addr, size, mtp, flags)); #endif #ifdef DEBUG_REDZONE @@ -524,10 +526,6 @@ if (memguard_cmp(mtp)) { return (addr); #endif /* !DEBUG_REDZONE */ -#ifdef DEBUG_MEMGUARD -} -#endif - /* Allocate a new, bigger (or smaller) block */ if ((newaddr = malloc(size, mtp, flags)) == NULL) return (NULL); @@ -559,7 +557,7 @@ static void kmeminit(void *dummy) { u_int8_t indx; - u_long mem_size; + u_long mem_size, tmp; int i; mtx_init(&malloc_mtx, "malloc", NULL, MTX_DEF); @@ -619,8 +617,13 @@ kmeminit(void *dummy) */ init_param3(vm_kmem_size / PAGE_SIZE); +#ifdef DEBUG_MEMGUARD + tmp = memguard_fudge(vm_kmem_size, vm_kmem_size_max); +#else + tmp = vm_kmem_size; +#endif kmem_map = kmem_suballoc(kernel_map, &kmembase, &kmemlimit, - vm_kmem_size, TRUE); + tmp, TRUE); kmem_map->system_map = 1; #ifdef DEBUG_MEMGUARD @@ -629,14 +632,7 @@ kmeminit(void *dummy) * replacement allocator used for detecting tamper-after-free * scenarios as they occur. It is only used for debugging. */ - vm_memguard_divisor = 10; - TUNABLE_INT_FETCH("vm.memguard.divisor", &vm_memguard_divisor); - - /* Pick a conservative value if provided value sucks. */ - if ((vm_memguard_divisor <= 0) || - ((vm_kmem_size / vm_memguard_divisor) == 0)) - vm_memguard_divisor = 10; - memguard_init(kmem_map, vm_kmem_size / vm_memguard_divisor); + memguard_init(kmem_map); #endif uma_startup2(); Modified: stable/8/sys/vm/memguard.c ============================================================================== --- stable/8/sys/vm/memguard.c Fri Sep 10 17:00:48 2010 (r212426) +++ stable/8/sys/vm/memguard.c Fri Sep 10 17:26:41 2010 (r212427) @@ -1,6 +1,7 @@ /* - * Copyright (c) 2005, - * Bosko Milekic . All rights reserved. + * Copyright (c) 2005, Bosko Milekic . + * Copyright (c) 2010 Isilon Systems, Inc. (http://www.isilon.com/) + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -36,6 +37,8 @@ __FBSDID("$FreeBSD$"); * See the memguard(9) man page for more information on using MemGuard. */ +#include "opt_vm.h" + #include #include #include @@ -47,26 +50,22 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include +#include #include #include -/* - * The maximum number of pages allowed per allocation. If you're using - * MemGuard to override very large items (> MAX_PAGES_PER_ITEM in size), - * you need to increase MAX_PAGES_PER_ITEM. - */ -#define MAX_PAGES_PER_ITEM 64 - SYSCTL_NODE(_vm, OID_AUTO, memguard, CTLFLAG_RW, NULL, "MemGuard data"); /* * The vm_memguard_divisor variable controls how much of kmem_map should be * reserved for MemGuard. */ -u_int vm_memguard_divisor; -SYSCTL_UINT(_vm_memguard, OID_AUTO, divisor, CTLFLAG_RD, &vm_memguard_divisor, +static u_int vm_memguard_divisor; +SYSCTL_UINT(_vm_memguard, OID_AUTO, divisor, CTLFLAG_RDTUN, + &vm_memguard_divisor, 0, "(kmem_size/memguard_divisor) == memguard submap size"); /* @@ -78,233 +77,372 @@ TUNABLE_STR("vm.memguard.desc", vm_memgu static int memguard_sysctl_desc(SYSCTL_HANDLER_ARGS) { - struct malloc_type_internal *mtip; - struct malloc_type_stats *mtsp; - struct malloc_type *mtp; - char desc[128]; - long bytes; - int error, i; + char desc[sizeof(vm_memguard_desc)]; + int error; strlcpy(desc, vm_memguard_desc, sizeof(desc)); error = sysctl_handle_string(oidp, desc, sizeof(desc), req); if (error != 0 || req->newptr == NULL) return (error); + mtx_lock(&malloc_mtx); /* - * We can change memory type when no memory has been allocated for it - * or when there is no such memory type yet (ie. it will be loaded with - * kernel module). + * If mtp is NULL, it will be initialized in memguard_cmp(). */ - bytes = 0; - mtx_lock(&malloc_mtx); - mtp = malloc_desc2type(desc); - if (mtp != NULL) { - mtip = mtp->ks_handle; - for (i = 0; i < MAXCPU; i++) { - mtsp = &mtip->mti_stats[i]; - bytes += mtsp->mts_memalloced; - bytes -= mtsp->mts_memfreed; - } - } - if (bytes > 0) - error = EBUSY; - else { - /* - * If mtp is NULL, it will be initialized in memguard_cmp(). - */ - vm_memguard_mtype = mtp; - strlcpy(vm_memguard_desc, desc, sizeof(vm_memguard_desc)); - } + vm_memguard_mtype = malloc_desc2type(desc); + strlcpy(vm_memguard_desc, desc, sizeof(vm_memguard_desc)); mtx_unlock(&malloc_mtx); return (error); } -SYSCTL_PROC(_vm_memguard, OID_AUTO, desc, CTLTYPE_STRING | CTLFLAG_RW, 0, 0, +SYSCTL_PROC(_vm_memguard, OID_AUTO, desc, + CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 0, memguard_sysctl_desc, "A", "Short description of memory type to monitor"); +static vm_map_t memguard_map = NULL; +static vm_offset_t memguard_cursor; +static vm_size_t memguard_mapsize; +static vm_size_t memguard_physlimit; +static u_long memguard_wasted; +static u_long memguard_wrap; +static u_long memguard_succ; +static u_long memguard_fail_kva; +static u_long memguard_fail_pgs; + +SYSCTL_ULONG(_vm_memguard, OID_AUTO, cursor, CTLFLAG_RD, + &memguard_cursor, 0, "MemGuard cursor"); +SYSCTL_ULONG(_vm_memguard, OID_AUTO, mapsize, CTLFLAG_RD, + &memguard_mapsize, 0, "MemGuard private vm_map size"); +SYSCTL_ULONG(_vm_memguard, OID_AUTO, phys_limit, CTLFLAG_RD, + &memguard_physlimit, 0, "Limit on MemGuard memory consumption"); +SYSCTL_ULONG(_vm_memguard, OID_AUTO, wasted, CTLFLAG_RD, + &memguard_wasted, 0, "Excess memory used through page promotion"); +SYSCTL_ULONG(_vm_memguard, OID_AUTO, wrapcnt, CTLFLAG_RD, + &memguard_wrap, 0, "MemGuard cursor wrap count"); +SYSCTL_ULONG(_vm_memguard, OID_AUTO, numalloc, CTLFLAG_RD, + &memguard_succ, 0, "Count of successful MemGuard allocations"); +SYSCTL_ULONG(_vm_memguard, OID_AUTO, fail_kva, CTLFLAG_RD, + &memguard_fail_kva, 0, "MemGuard failures due to lack of KVA"); +SYSCTL_ULONG(_vm_memguard, OID_AUTO, fail_pgs, CTLFLAG_RD, + &memguard_fail_pgs, 0, "MemGuard failures due to lack of pages"); + +#define MG_GUARD 0x001 +#define MG_ALLLARGE 0x002 +static int memguard_options = MG_GUARD; +TUNABLE_INT("vm.memguard.options", &memguard_options); +SYSCTL_INT(_vm_memguard, OID_AUTO, options, CTLFLAG_RW, + &memguard_options, 0, + "MemGuard options:\n" + "\t0x001 - add guard pages around each allocation\n" + "\t0x002 - always use MemGuard for allocations over a page"); + +static u_int memguard_minsize; +static u_long memguard_minsize_reject; +SYSCTL_UINT(_vm_memguard, OID_AUTO, minsize, CTLFLAG_RW, + &memguard_minsize, 0, "Minimum size for page promotion"); +SYSCTL_ULONG(_vm_memguard, OID_AUTO, minsize_reject, CTLFLAG_RD, + &memguard_minsize_reject, 0, "# times rejected for size"); + +static u_int memguard_frequency; +static u_long memguard_frequency_hits; +TUNABLE_INT("vm.memguard.frequency", &memguard_frequency); +SYSCTL_UINT(_vm_memguard, OID_AUTO, frequency, CTLFLAG_RW, + &memguard_frequency, 0, "Times in 100000 that MemGuard will randomly run"); +SYSCTL_ULONG(_vm_memguard, OID_AUTO, frequency_hits, CTLFLAG_RD, + &memguard_frequency_hits, 0, "# times MemGuard randomly chose"); + + /* - * Global MemGuard data. + * Return a fudged value to be used for vm_kmem_size for allocating + * the kmem_map. The memguard memory will be a submap. */ -static vm_map_t memguard_map; -static unsigned long memguard_mapsize; -static unsigned long memguard_mapused; -struct memguard_entry { - STAILQ_ENTRY(memguard_entry) entries; - void *ptr; -}; -static struct memguard_fifo { - struct memguard_entry *stqh_first; - struct memguard_entry **stqh_last; - int index; -} memguard_fifo_pool[MAX_PAGES_PER_ITEM]; - -/* - * Local prototypes. - */ -static void memguard_guard(void *addr, int numpgs); -static void memguard_unguard(void *addr, int numpgs); -static struct memguard_fifo *vtomgfifo(vm_offset_t va); -static void vsetmgfifo(vm_offset_t va, struct memguard_fifo *mgfifo); -static void vclrmgfifo(vm_offset_t va); - -/* - * Local macros. MemGuard data is global, so replace these with whatever - * your system uses to protect global data (if it is kernel-level - * parallelized). This is for porting among BSDs. - */ -#define MEMGUARD_CRIT_SECTION_DECLARE static struct mtx memguard_mtx -#define MEMGUARD_CRIT_SECTION_INIT \ - mtx_init(&memguard_mtx, "MemGuard mtx", NULL, MTX_DEF) -#define MEMGUARD_CRIT_SECTION_ENTER mtx_lock(&memguard_mtx) -#define MEMGUARD_CRIT_SECTION_EXIT mtx_unlock(&memguard_mtx) -MEMGUARD_CRIT_SECTION_DECLARE; +unsigned long +memguard_fudge(unsigned long km_size, unsigned long km_max) +{ + u_long mem_pgs = cnt.v_page_count; + + vm_memguard_divisor = 10; + TUNABLE_INT_FETCH("vm.memguard.divisor", &vm_memguard_divisor); + + /* Pick a conservative value if provided value sucks. */ + if ((vm_memguard_divisor <= 0) || + ((km_size / vm_memguard_divisor) == 0)) + vm_memguard_divisor = 10; + /* + * Limit consumption of physical pages to + * 1/vm_memguard_divisor of system memory. If the KVA is + * smaller than this then the KVA limit comes into play first. + * This prevents memguard's page promotions from completely + * using up memory, since most malloc(9) calls are sub-page. + */ + memguard_physlimit = (mem_pgs / vm_memguard_divisor) * PAGE_SIZE; + /* + * We want as much KVA as we can take safely. Use at most our + * allotted fraction of kmem_max. Limit this to twice the + * physical memory to avoid using too much memory as pagetable + * pages. + */ + memguard_mapsize = km_max / vm_memguard_divisor; + /* size must be multiple of PAGE_SIZE */ + memguard_mapsize = round_page(memguard_mapsize); + if (memguard_mapsize / (2 * PAGE_SIZE) > mem_pgs) + memguard_mapsize = mem_pgs * 2 * PAGE_SIZE; + if (km_size + memguard_mapsize > km_max) + return (km_max); + return (km_size + memguard_mapsize); +} /* * Initialize the MemGuard mock allocator. All objects from MemGuard come * out of a single VM map (contiguous chunk of address space). */ void -memguard_init(vm_map_t parent_map, unsigned long size) +memguard_init(vm_map_t parent_map) { - char *base, *limit; - int i; - - /* size must be multiple of PAGE_SIZE */ - size /= PAGE_SIZE; - size++; - size *= PAGE_SIZE; + vm_offset_t base, limit; - memguard_map = kmem_suballoc(parent_map, (vm_offset_t *)&base, - (vm_offset_t *)&limit, (vm_size_t)size, FALSE); + memguard_map = kmem_suballoc(parent_map, &base, &limit, + memguard_mapsize, FALSE); memguard_map->system_map = 1; - memguard_mapsize = size; - memguard_mapused = 0; - - MEMGUARD_CRIT_SECTION_INIT; - MEMGUARD_CRIT_SECTION_ENTER; - for (i = 0; i < MAX_PAGES_PER_ITEM; i++) { - STAILQ_INIT(&memguard_fifo_pool[i]); - memguard_fifo_pool[i].index = i; - } - MEMGUARD_CRIT_SECTION_EXIT; + KASSERT(memguard_mapsize == limit - base, + ("Expected %lu, got %lu", (u_long)memguard_mapsize, + (u_long)(limit - base))); + memguard_cursor = base; printf("MEMGUARD DEBUGGING ALLOCATOR INITIALIZED:\n"); - printf("\tMEMGUARD map base: %p\n", base); - printf("\tMEMGUARD map limit: %p\n", limit); - printf("\tMEMGUARD map size: %ld (Bytes)\n", size); + printf("\tMEMGUARD map base: 0x%lx\n", (u_long)base); + printf("\tMEMGUARD map limit: 0x%lx\n", (u_long)limit); + printf("\tMEMGUARD map size: %jd KBytes\n", + (uintmax_t)memguard_mapsize >> 10); } /* - * Allocate a single object of specified size with specified flags (either - * M_WAITOK or M_NOWAIT). + * Run things that can't be done as early as memguard_init(). + */ +static void +memguard_sysinit(void) +{ + struct sysctl_oid_list *parent; + + parent = SYSCTL_STATIC_CHILDREN(_vm_memguard); + + SYSCTL_ADD_ULONG(NULL, parent, OID_AUTO, "mapstart", CTLFLAG_RD, + &memguard_map->min_offset, "MemGuard KVA base"); + SYSCTL_ADD_ULONG(NULL, parent, OID_AUTO, "maplimit", CTLFLAG_RD, + &memguard_map->max_offset, "MemGuard KVA end"); + SYSCTL_ADD_ULONG(NULL, parent, OID_AUTO, "mapused", CTLFLAG_RD, + &memguard_map->size, "MemGuard KVA used"); +} +SYSINIT(memguard, SI_SUB_KLD, SI_ORDER_ANY, memguard_sysinit, NULL); + +/* + * v2sizep() converts a virtual address of the first page allocated for + * an item to a pointer to u_long recording the size of the original + * allocation request. + * + * This routine is very similar to those defined by UMA in uma_int.h. + * The difference is that this routine stores the originally allocated + * size in one of the page's fields that is unused when the page is + * wired rather than the object field, which is used. + */ +static u_long * +v2sizep(vm_offset_t va) +{ + vm_paddr_t pa; + struct vm_page *p; + + pa = pmap_kextract(va); + if (pa == 0) + panic("MemGuard detected double-free of %p", (void *)va); + p = PHYS_TO_VM_PAGE(pa); + KASSERT(p->wire_count != 0 && p->queue == PQ_NONE, + ("MEMGUARD: Expected wired page %p in vtomgfifo!", p)); + return ((u_long *)&p->pageq.tqe_next); +} + +/* + * Allocate a single object of specified size with specified flags + * (either M_WAITOK or M_NOWAIT). */ void * -memguard_alloc(unsigned long size, int flags) +memguard_alloc(unsigned long req_size, int flags) { - void *obj; - struct memguard_entry *e = NULL; - int numpgs; - - numpgs = size / PAGE_SIZE; - if ((size % PAGE_SIZE) != 0) - numpgs++; - if (numpgs > MAX_PAGES_PER_ITEM) - panic("MEMGUARD: You must increase MAX_PAGES_PER_ITEM " \ - "in memguard.c (requested: %d pages)", numpgs); - if (numpgs == 0) - return NULL; - - /* - * If we haven't exhausted the memguard_map yet, allocate from - * it and grab a new page, even if we have recycled pages in our - * FIFO. This is because we wish to allow recycled pages to live - * guarded in the FIFO for as long as possible in order to catch - * even very late tamper-after-frees, even though it means that - * we end up wasting more memory, this is only a DEBUGGING allocator - * after all. - */ - MEMGUARD_CRIT_SECTION_ENTER; - if (memguard_mapused >= memguard_mapsize) { - e = STAILQ_FIRST(&memguard_fifo_pool[numpgs - 1]); - if (e != NULL) { - STAILQ_REMOVE(&memguard_fifo_pool[numpgs - 1], e, - memguard_entry, entries); - MEMGUARD_CRIT_SECTION_EXIT; - obj = e->ptr; - free(e, M_TEMP); - memguard_unguard(obj, numpgs); - if (flags & M_ZERO) - bzero(obj, PAGE_SIZE * numpgs); - return obj; + vm_offset_t addr; + u_long size_p, size_v; + int do_guard, rv; + + size_p = round_page(req_size); + if (size_p == 0) + return (NULL); + /* + * To ensure there are holes on both sides of the allocation, + * request 2 extra pages of KVA. We will only actually add a + * vm_map_entry and get pages for the original request. Save + * the value of memguard_options so we have a consistent + * value. + */ + size_v = size_p; + do_guard = (memguard_options & MG_GUARD) != 0; + if (do_guard) + size_v += 2 * PAGE_SIZE; + + vm_map_lock(memguard_map); + /* + * When we pass our memory limit, reject sub-page allocations. + * Page-size and larger allocations will use the same amount + * of physical memory whether we allocate or hand off to + * uma_large_alloc(), so keep those. + */ + if (memguard_map->size >= memguard_physlimit && + req_size < PAGE_SIZE) { + addr = (vm_offset_t)NULL; + memguard_fail_pgs++; + goto out; + } + /* + * Keep a moving cursor so we don't recycle KVA as long as + * possible. It's not perfect, since we don't know in what + * order previous allocations will be free'd, but it's simple + * and fast, and requires O(1) additional storage if guard + * pages are not used. + * + * XXX This scheme will lead to greater fragmentation of the + * map, unless vm_map_findspace() is tweaked. + */ + for (;;) { + rv = vm_map_findspace(memguard_map, memguard_cursor, + size_v, &addr); + if (rv == KERN_SUCCESS) + break; + /* + * The map has no space. This may be due to + * fragmentation, or because the cursor is near the + * end of the map. + */ + if (memguard_cursor == vm_map_min(memguard_map)) { + memguard_fail_kva++; + addr = (vm_offset_t)NULL; + goto out; } - MEMGUARD_CRIT_SECTION_EXIT; - if (flags & M_WAITOK) - panic("MEMGUARD: Failed with M_WAITOK: " \ - "memguard_map too small"); - return NULL; + memguard_wrap++; + memguard_cursor = vm_map_min(memguard_map); } - memguard_mapused += (PAGE_SIZE * numpgs); - MEMGUARD_CRIT_SECTION_EXIT; - - obj = (void *)kmem_malloc(memguard_map, PAGE_SIZE * numpgs, flags); - if (obj != NULL) { - vsetmgfifo((vm_offset_t)obj, &memguard_fifo_pool[numpgs - 1]); - if (flags & M_ZERO) - bzero(obj, PAGE_SIZE * numpgs); - } else { - MEMGUARD_CRIT_SECTION_ENTER; - memguard_mapused -= (PAGE_SIZE * numpgs); - MEMGUARD_CRIT_SECTION_EXIT; + if (do_guard) + addr += PAGE_SIZE; + rv = kmem_back(memguard_map, addr, size_p, flags); + if (rv != KERN_SUCCESS) { + memguard_fail_pgs++; + addr = (vm_offset_t)NULL; + goto out; } - return obj; + memguard_cursor = addr + size_p; + *v2sizep(trunc_page(addr)) = req_size; + memguard_succ++; + if (req_size < PAGE_SIZE) { + memguard_wasted += (PAGE_SIZE - req_size); + if (do_guard) { + /* + * Align the request to 16 bytes, and return + * an address near the end of the page, to + * better detect array overrun. + */ + req_size = roundup2(req_size, 16); + addr += (PAGE_SIZE - req_size); + } + } +out: + vm_map_unlock(memguard_map); + return ((void *)addr); +} + +int +is_memguard_addr(void *addr) +{ + vm_offset_t a = (vm_offset_t)(uintptr_t)addr; + + return (a >= memguard_map->min_offset && a < memguard_map->max_offset); } /* * Free specified single object. */ void -memguard_free(void *addr) +memguard_free(void *ptr) { - struct memguard_entry *e; - struct memguard_fifo *mgfifo; - int idx; - int *temp; - - addr = (void *)trunc_page((unsigned long)addr); - - /* - * Page should not be guarded by now, so force a write. - * The purpose of this is to increase the likelihood of catching a - * double-free, but not necessarily a tamper-after-free (the second - * thread freeing might not write before freeing, so this forces it - * to and, subsequently, trigger a fault). - */ - temp = (int *)((unsigned long)addr + (PAGE_SIZE/2)); /* in page */ - *temp = 0xd34dc0d3; - - mgfifo = vtomgfifo((vm_offset_t)addr); - idx = mgfifo->index; - memguard_guard(addr, idx + 1); - e = malloc(sizeof(struct memguard_entry), M_TEMP, M_NOWAIT); - if (e == NULL) { - MEMGUARD_CRIT_SECTION_ENTER; - memguard_mapused -= (PAGE_SIZE * (idx + 1)); - MEMGUARD_CRIT_SECTION_EXIT; - memguard_unguard(addr, idx + 1); /* just in case */ - vclrmgfifo((vm_offset_t)addr); - kmem_free(memguard_map, (vm_offset_t)addr, - PAGE_SIZE * (idx + 1)); - return; - } - e->ptr = addr; - MEMGUARD_CRIT_SECTION_ENTER; - STAILQ_INSERT_TAIL(mgfifo, e, entries); - MEMGUARD_CRIT_SECTION_EXIT; + vm_offset_t addr; + u_long req_size, size; + char *temp; + int i; + + addr = trunc_page((uintptr_t)ptr); + req_size = *v2sizep(addr); + size = round_page(req_size); + + /* + * Page should not be guarded right now, so force a write. + * The purpose of this is to increase the likelihood of + * catching a double-free, but not necessarily a + * tamper-after-free (the second thread freeing might not + * write before freeing, so this forces it to and, + * subsequently, trigger a fault). + */ + temp = ptr; + for (i = 0; i < size; i += PAGE_SIZE) + temp[i] = 'M'; + + /* + * This requires carnal knowledge of the implementation of + * kmem_free(), but since we've already replaced kmem_malloc() + * above, it's not really any worse. We want to use the + * vm_map lock to serialize updates to memguard_wasted, since + * we had the lock at increment. + */ + vm_map_lock(memguard_map); + if (req_size < PAGE_SIZE) + memguard_wasted -= (PAGE_SIZE - req_size); + (void)vm_map_delete(memguard_map, addr, addr + size); + vm_map_unlock(memguard_map); +} + +/* + * Re-allocate an allocation that was originally guarded. + */ +void * +memguard_realloc(void *addr, unsigned long size, struct malloc_type *mtp, + int flags) +{ + void *newaddr; + u_long old_size; + + /* + * Allocate the new block. Force the allocation to be guarded + * as the original may have been guarded through random + * chance, and that should be preserved. + */ + if ((newaddr = memguard_alloc(size, flags)) == NULL) + return (NULL); + + /* Copy over original contents. */ + old_size = *v2sizep(trunc_page((uintptr_t)addr)); + bcopy(addr, newaddr, min(size, old_size)); + memguard_free(addr); + return (newaddr); } int -memguard_cmp(struct malloc_type *mtp) +memguard_cmp(struct malloc_type *mtp, unsigned long size) { + if (size < memguard_minsize) { + memguard_minsize_reject++; + return (0); + } + if ((memguard_options & MG_ALLLARGE) != 0 && size >= PAGE_SIZE) + return (1); + if (memguard_frequency > 0 && + (random() % 100000) < memguard_frequency) { + memguard_frequency_hits++; + return (1); + } #if 1 /* * The safest way of comparsion is to always compare short description @@ -328,78 +466,3 @@ memguard_cmp(struct malloc_type *mtp) return (0); #endif } - -/* - * Guard a page containing specified object (make it read-only so that - * future writes to it fail). - */ -static void -memguard_guard(void *addr, int numpgs) -{ - void *a = (void *)trunc_page((unsigned long)addr); - if (vm_map_protect(memguard_map, (vm_offset_t)a, - (vm_offset_t)((unsigned long)a + (PAGE_SIZE * numpgs)), - VM_PROT_READ, FALSE) != KERN_SUCCESS) - panic("MEMGUARD: Unable to guard page!"); -} - -/* - * Unguard a page containing specified object (make it read-and-write to - * allow full data access). - */ -static void -memguard_unguard(void *addr, int numpgs) -{ - void *a = (void *)trunc_page((unsigned long)addr); - if (vm_map_protect(memguard_map, (vm_offset_t)a, - (vm_offset_t)((unsigned long)a + (PAGE_SIZE * numpgs)), - VM_PROT_DEFAULT, FALSE) != KERN_SUCCESS) - panic("MEMGUARD: Unable to unguard page!"); -} - -/* - * vtomgfifo() converts a virtual address of the first page allocated for - * an item to a memguard_fifo_pool reference for the corresponding item's - * size. - * - * vsetmgfifo() sets a reference in an underlying page for the specified - * virtual address to an appropriate memguard_fifo_pool. - * - * These routines are very similar to those defined by UMA in uma_int.h. - * The difference is that these routines store the mgfifo in one of the - * page's fields that is unused when the page is wired rather than the - * object field, which is used. - */ -static struct memguard_fifo * -vtomgfifo(vm_offset_t va) -{ - vm_page_t p; - struct memguard_fifo *mgfifo; - - p = PHYS_TO_VM_PAGE(pmap_kextract(va)); - KASSERT(p->wire_count != 0 && p->queue == PQ_NONE, - ("MEMGUARD: Expected wired page in vtomgfifo!")); - mgfifo = (struct memguard_fifo *)p->pageq.tqe_next; - return mgfifo; -} - -static void -vsetmgfifo(vm_offset_t va, struct memguard_fifo *mgfifo) -{ - vm_page_t p; - - p = PHYS_TO_VM_PAGE(pmap_kextract(va)); - KASSERT(p->wire_count != 0 && p->queue == PQ_NONE, - ("MEMGUARD: Expected wired page in vsetmgfifo!")); - p->pageq.tqe_next = (vm_page_t)mgfifo; -} - -static void vclrmgfifo(vm_offset_t va) -{ - vm_page_t p; - - p = PHYS_TO_VM_PAGE(pmap_kextract(va)); - KASSERT(p->wire_count != 0 && p->queue == PQ_NONE, - ("MEMGUARD: Expected wired page in vclrmgfifo!")); - p->pageq.tqe_next = NULL; -} Modified: stable/8/sys/vm/memguard.h ============================================================================== --- stable/8/sys/vm/memguard.h Fri Sep 10 17:00:48 2010 (r212426) +++ stable/8/sys/vm/memguard.h Fri Sep 10 17:26:41 2010 (r212427) @@ -26,9 +26,30 @@ * $FreeBSD$ */ -extern u_int vm_memguard_divisor; +#ifndef _VM_MEMGUARD_H_ +#define _VM_MEMGUARD_H_ -void memguard_init(vm_map_t parent_map, unsigned long size); -void *memguard_alloc(unsigned long size, int flags); -void memguard_free(void *addr); -int memguard_cmp(struct malloc_type *mtp); +#include "opt_vm.h" + +struct malloc_type; +struct vm_map; + +#ifdef DEBUG_MEMGUARD +unsigned long memguard_fudge(unsigned long, unsigned long); +void memguard_init(struct vm_map *); +void *memguard_alloc(unsigned long, int); +void *memguard_realloc(void *, unsigned long, struct malloc_type *, int); +void memguard_free(void *); +int memguard_cmp(struct malloc_type *, unsigned long); +int is_memguard_addr(void *); +#else +#define memguard_fudge(size, xxx) (size) +#define memguard_init(map) do { } while (0) +#define memguard_alloc(size, flags) NULL +#define memguard_realloc(a, s, mtp, f) NULL +#define memguard_free(addr) do { } while (0) +#define memguard_cmp(mtp, size) 0 +#define is_memguard_addr(addr) 0 +#endif + +#endif /* _VM_MEMGUARD_H_ */ Modified: stable/8/sys/vm/vm_extern.h ============================================================================== --- stable/8/sys/vm/vm_extern.h Fri Sep 10 17:00:48 2010 (r212426) +++ stable/8/sys/vm/vm_extern.h Fri Sep 10 17:26:41 2010 (r212427) @@ -52,6 +52,7 @@ void kmem_free(vm_map_t, vm_offset_t, vm void kmem_free_wakeup(vm_map_t, vm_offset_t, vm_size_t); void kmem_init(vm_offset_t, vm_offset_t); vm_offset_t kmem_malloc(vm_map_t map, vm_size_t size, int flags); +int kmem_back(vm_map_t, vm_offset_t, vm_size_t, int); vm_map_t kmem_suballoc(vm_map_t, vm_offset_t *, vm_offset_t *, vm_size_t, boolean_t); void swapout_procs(int); Modified: stable/8/sys/vm/vm_kern.c ============================================================================== --- stable/8/sys/vm/vm_kern.c Fri Sep 10 17:00:48 2010 (r212426) +++ stable/8/sys/vm/vm_kern.c Fri Sep 10 17:26:41 2010 (r212427) @@ -272,11 +272,8 @@ kmem_malloc(map, size, flags) vm_size_t size; int flags; { - vm_offset_t offset, i; - vm_map_entry_t entry; vm_offset_t addr; - vm_page_t m; - int pflags; + int i, rv; size = round_page(size); *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-stable@FreeBSD.ORG Fri Sep 10 21:53:47 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 835B6106566B; Fri, 10 Sep 2010 21:53:47 +0000 (UTC) (envelope-from mdf@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 6F4068FC08; Fri, 10 Sep 2010 21:53:47 +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 o8ALrlkv092062; Fri, 10 Sep 2010 21:53:47 GMT (envelope-from mdf@svn.freebsd.org) Received: (from mdf@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o8ALrl93092055; Fri, 10 Sep 2010 21:53:47 GMT (envelope-from mdf@svn.freebsd.org) Message-Id: <201009102153.o8ALrl93092055@svn.freebsd.org> From: Matthew D Fleming Date: Fri, 10 Sep 2010 21:53:47 +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: r212437 - in stable/7: share/man/man9 sys/kern sys/vm X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Sep 2010 21:53:47 -0000 Author: mdf Date: Fri Sep 10 21:53:47 2010 New Revision: 212437 URL: http://svn.freebsd.org/changeset/base/212437 Log: MFC r211194, r211229, r212058, r212063: memguard(9) rewrite r211194: Rework memguard(9) to reserve significantly more KVA to detect use-after-free over a longer time. Also release the backing pages of a guarded allocation at free(9) time to reduce the overhead of using memguard(9). Allow setting and varying the malloc type at run-time. Add knobs to allow: - randomly guarding memory - adding un-backed KVA guard pages to detect underflow and overflow - a lower limit on the size of allocations that are guarded r211229: Fix compile. It seemed better to have memguard.c include opt_vm.h in case future compile-time knobs were added that it wants to use. Also add include guards and forward declarations to vm/memguard.h. r212058: The realloc case for memguard(9) will copy too many bytes when reallocating to a smaller-sized allocation. Fix this issue. r212063: Have memguard(9) crash with an easier-to-debug message on double-free. Modified: stable/7/share/man/man9/memguard.9 stable/7/sys/kern/kern_malloc.c stable/7/sys/vm/memguard.c stable/7/sys/vm/memguard.h stable/7/sys/vm/vm_extern.h stable/7/sys/vm/vm_kern.c Directory Properties: stable/7/share/man/ (props changed) stable/7/share/man/man1/ (props changed) stable/7/share/man/man3/ (props changed) stable/7/share/man/man4/ (props changed) stable/7/share/man/man5/ (props changed) stable/7/share/man/man7/ (props changed) stable/7/share/man/man8/ (props changed) stable/7/share/man/man9/ (props changed) 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/share/man/man9/memguard.9 ============================================================================== --- stable/7/share/man/man9/memguard.9 Fri Sep 10 21:45:42 2010 (r212436) +++ stable/7/share/man/man9/memguard.9 Fri Sep 10 21:53:47 2010 (r212437) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd January 31, 2006 +.Dd August 2, 2010 .Dt MEMGUARD 9 .Os .Sh NAME @@ -41,54 +41,107 @@ multithreaded kernels where race conditi .Pp Currently, .Nm -can only take over +can take over .Fn malloc , .Fn realloc and .Fn free -for a particular malloc type. +for a single malloc type. +.Nm +can also guard all allocations larger than +.Dv PAGE_SIZE , +and can guard a random fraction of all allocations. +There is also a knob to prevent allocations smaller than a specified +size from being guarded, to limit memory waste. .Sh EXAMPLES To use .Nm -for memory type compiled into the kernel, one has to add the -following line to the +for a memory type, either add an entry to .Pa /boot/loader.conf : .Bd -literal -offset indent vm.memguard.desc= .Ed .Pp -Where -.Ar memory_type -is a short description of memory type to monitor. -The short description of memory type is the second argument to -.Xr MALLOC_DEFINE 9 , -so one has to find it in the kernel source. -.Pp -To use -.Nm -for memory type defined in a kernel module, one has to set +Or set the .Va vm.memguard.desc .Xr sysctl 8 -variable before loading the module: +variable at run-time: .Bd -literal -offset indent sysctl vm.memguard.desc= .Ed .Pp +Where +.Ar memory_type +is a short description of the memory type to monitor. +Only allocations from that +.Ar memory_type +made after +.Va vm.memguard.desc +is set will potentially be guarded. +If +.Va vm.memguard.desc +is modified at run-time then only allocations of the new +.Ar memory_type +will potentially be guarded once the +.Xr sysctl 8 +is set. +Existing guarded allocations will still be properly released by +.Xr free 9 . +.Pp +The short description of a +.Xr malloc 9 +type is the second argument to +.Xr MALLOC_DEFINE 9 , +so one has to find it in the kernel source. +.Pp The .Va vm.memguard.divisor -boot-time tunable is used to scale how much of -.Va kmem_map -one wants to allocate for -.Nm . -The default is 10, so -.Va kmem_size Ns /10 -bytes will be used. -The -.Va kmem_size -value can be obtained via the -.Va vm.kmem_size -.Xr sysctl 8 -variable. +boot-time tunable is used to scale how much of the system's physical +memory +.Nm +is allowed to consume. +The default is 10, so up to +.Va cnt.v_page_count Ns /10 +pages can be used. +.Nm +will reserve +.Va vm_kmem_max +/ +.Va vm.memguard.divisor +bytes of virtual address space, limited by twice the physical memory +size. +The physical limit is reported as +.Va vm.memguard.phys_limit +and the virtual space reserved for +.Nm +is reported as +.Va vm.memguard.mapsize . +.Pp +.Nm +will not do page promotions for any allocation smaller than +.Va vm.memguard.minsize +bytes. +The default is 0, meaning all allocations can potentially be guarded. +.Nm +can guard sufficiently large allocations randomly, with average +frequency of every one in 100000 / +.Va vm.memguard.frequency +allocations. +The default is 0, meaning no allocations are randomly guarded. +.Pp +.Nm +can optionally add unmapped guard pages around each allocation to +detect overflow and underflow, if +.Va vm.memguard.options +has the 1 bit set. +This option is enabled by default. +.Nm +will optionally guard all allocations of +.Dv PAGE_SIZE +or larger if +.Va vm.memguard.options +has the 2 bit set. +This option is off by default. .Sh SEE ALSO .Xr sysctl 8 , .Xr vmstat 8 , @@ -102,10 +155,13 @@ first appeared in .Sh AUTHORS .An -nosplit .Nm -was written by +was originally written by .An Bosko Milekic Aq bmilekic@FreeBSD.org . -This manual page was written by +This manual page was originally written by .An Christian Brueffer Aq brueffer@FreeBSD.org . +Additions have been made by +.An Matthew Fleming Aq mdf@FreeBSD.org +to both the implementation and the documentation. .Sh BUGS Currently, it is not possible to override UMA .Xr zone 9 Modified: stable/7/sys/kern/kern_malloc.c ============================================================================== --- stable/7/sys/kern/kern_malloc.c Fri Sep 10 21:45:42 2010 (r212436) +++ stable/7/sys/kern/kern_malloc.c Fri Sep 10 21:53:47 2010 (r212437) @@ -365,8 +365,12 @@ malloc(unsigned long size, struct malloc ("malloc(M_WAITOK) in interrupt context")); #ifdef DEBUG_MEMGUARD - if (memguard_cmp(mtp)) - return memguard_alloc(size, flags); + if (memguard_cmp(mtp, size)) { + va = memguard_alloc(size, flags); + if (va != NULL) + return (va); + /* This is unfortunate but should not be fatal. */ + } #endif #ifdef DEBUG_REDZONE @@ -427,7 +431,7 @@ free(void *addr, struct malloc_type *mtp return; #ifdef DEBUG_MEMGUARD - if (memguard_cmp(mtp)) { + if (is_memguard_addr(addr)) { memguard_free(addr); return; } @@ -495,10 +499,8 @@ realloc(void *addr, unsigned long size, */ #ifdef DEBUG_MEMGUARD -if (memguard_cmp(mtp)) { - slab = NULL; - alloc = size; -} else { + if (is_memguard_addr(addr)) + return (memguard_realloc(addr, size, mtp, flags)); #endif #ifdef DEBUG_REDZONE @@ -523,10 +525,6 @@ if (memguard_cmp(mtp)) { return (addr); #endif /* !DEBUG_REDZONE */ -#ifdef DEBUG_MEMGUARD -} -#endif - /* Allocate a new, bigger (or smaller) block */ if ((newaddr = malloc(size, mtp, flags)) == NULL) return (NULL); @@ -558,7 +556,7 @@ static void kmeminit(void *dummy) { u_int8_t indx; - u_long mem_size; + u_long mem_size, tmp; int i; mtx_init(&malloc_mtx, "malloc", NULL, MTX_DEF); @@ -622,8 +620,13 @@ kmeminit(void *dummy) */ init_param3(vm_kmem_size / PAGE_SIZE); +#ifdef DEBUG_MEMGUARD + tmp = memguard_fudge(vm_kmem_size, vm_kmem_size_max); +#else + tmp = vm_kmem_size; +#endif kmem_map = kmem_suballoc(kernel_map, &kmembase, &kmemlimit, - vm_kmem_size, TRUE); + tmp, TRUE); kmem_map->system_map = 1; #ifdef DEBUG_MEMGUARD @@ -632,14 +635,7 @@ kmeminit(void *dummy) * replacement allocator used for detecting tamper-after-free * scenarios as they occur. It is only used for debugging. */ - vm_memguard_divisor = 10; - TUNABLE_INT_FETCH("vm.memguard.divisor", &vm_memguard_divisor); - - /* Pick a conservative value if provided value sucks. */ - if ((vm_memguard_divisor <= 0) || - ((vm_kmem_size / vm_memguard_divisor) == 0)) - vm_memguard_divisor = 10; - memguard_init(kmem_map, vm_kmem_size / vm_memguard_divisor); + memguard_init(kmem_map); #endif uma_startup2(); Modified: stable/7/sys/vm/memguard.c ============================================================================== --- stable/7/sys/vm/memguard.c Fri Sep 10 21:45:42 2010 (r212436) +++ stable/7/sys/vm/memguard.c Fri Sep 10 21:53:47 2010 (r212437) @@ -1,6 +1,7 @@ /* - * Copyright (c) 2005, - * Bosko Milekic . All rights reserved. + * Copyright (c) 2005, Bosko Milekic . + * Copyright (c) 2010 Isilon Systems, Inc. (http://www.isilon.com/) + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -36,6 +37,8 @@ __FBSDID("$FreeBSD$"); * See the memguard(9) man page for more information on using MemGuard. */ +#include "opt_vm.h" + #include #include #include @@ -47,26 +50,22 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include +#include #include #include -/* - * The maximum number of pages allowed per allocation. If you're using - * MemGuard to override very large items (> MAX_PAGES_PER_ITEM in size), - * you need to increase MAX_PAGES_PER_ITEM. - */ -#define MAX_PAGES_PER_ITEM 64 - SYSCTL_NODE(_vm, OID_AUTO, memguard, CTLFLAG_RW, NULL, "MemGuard data"); /* * The vm_memguard_divisor variable controls how much of kmem_map should be * reserved for MemGuard. */ -u_int vm_memguard_divisor; -SYSCTL_UINT(_vm_memguard, OID_AUTO, divisor, CTLFLAG_RD, &vm_memguard_divisor, +static u_int vm_memguard_divisor; +SYSCTL_UINT(_vm_memguard, OID_AUTO, divisor, CTLFLAG_RDTUN, + &vm_memguard_divisor, 0, "(kmem_size/memguard_divisor) == memguard submap size"); /* @@ -78,233 +77,372 @@ TUNABLE_STR("vm.memguard.desc", vm_memgu static int memguard_sysctl_desc(SYSCTL_HANDLER_ARGS) { - struct malloc_type_internal *mtip; - struct malloc_type_stats *mtsp; - struct malloc_type *mtp; - char desc[128]; - long bytes; - int error, i; + char desc[sizeof(vm_memguard_desc)]; + int error; strlcpy(desc, vm_memguard_desc, sizeof(desc)); error = sysctl_handle_string(oidp, desc, sizeof(desc), req); if (error != 0 || req->newptr == NULL) return (error); + mtx_lock(&malloc_mtx); /* - * We can change memory type when no memory has been allocated for it - * or when there is no such memory type yet (ie. it will be loaded with - * kernel module). + * If mtp is NULL, it will be initialized in memguard_cmp(). */ - bytes = 0; - mtx_lock(&malloc_mtx); - mtp = malloc_desc2type(desc); - if (mtp != NULL) { - mtip = mtp->ks_handle; - for (i = 0; i < MAXCPU; i++) { - mtsp = &mtip->mti_stats[i]; - bytes += mtsp->mts_memalloced; - bytes -= mtsp->mts_memfreed; - } - } - if (bytes > 0) - error = EBUSY; - else { - /* - * If mtp is NULL, it will be initialized in memguard_cmp(). - */ - vm_memguard_mtype = mtp; - strlcpy(vm_memguard_desc, desc, sizeof(vm_memguard_desc)); - } + vm_memguard_mtype = malloc_desc2type(desc); + strlcpy(vm_memguard_desc, desc, sizeof(vm_memguard_desc)); mtx_unlock(&malloc_mtx); return (error); } -SYSCTL_PROC(_vm_memguard, OID_AUTO, desc, CTLTYPE_STRING | CTLFLAG_RW, 0, 0, +SYSCTL_PROC(_vm_memguard, OID_AUTO, desc, + CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 0, memguard_sysctl_desc, "A", "Short description of memory type to monitor"); +static vm_map_t memguard_map = NULL; +static vm_offset_t memguard_cursor; +static vm_size_t memguard_mapsize; +static vm_size_t memguard_physlimit; +static u_long memguard_wasted; +static u_long memguard_wrap; +static u_long memguard_succ; +static u_long memguard_fail_kva; +static u_long memguard_fail_pgs; + +SYSCTL_ULONG(_vm_memguard, OID_AUTO, cursor, CTLFLAG_RD, + &memguard_cursor, 0, "MemGuard cursor"); +SYSCTL_ULONG(_vm_memguard, OID_AUTO, mapsize, CTLFLAG_RD, + &memguard_mapsize, 0, "MemGuard private vm_map size"); +SYSCTL_ULONG(_vm_memguard, OID_AUTO, phys_limit, CTLFLAG_RD, + &memguard_physlimit, 0, "Limit on MemGuard memory consumption"); +SYSCTL_ULONG(_vm_memguard, OID_AUTO, wasted, CTLFLAG_RD, + &memguard_wasted, 0, "Excess memory used through page promotion"); +SYSCTL_ULONG(_vm_memguard, OID_AUTO, wrapcnt, CTLFLAG_RD, + &memguard_wrap, 0, "MemGuard cursor wrap count"); +SYSCTL_ULONG(_vm_memguard, OID_AUTO, numalloc, CTLFLAG_RD, + &memguard_succ, 0, "Count of successful MemGuard allocations"); +SYSCTL_ULONG(_vm_memguard, OID_AUTO, fail_kva, CTLFLAG_RD, + &memguard_fail_kva, 0, "MemGuard failures due to lack of KVA"); +SYSCTL_ULONG(_vm_memguard, OID_AUTO, fail_pgs, CTLFLAG_RD, + &memguard_fail_pgs, 0, "MemGuard failures due to lack of pages"); + +#define MG_GUARD 0x001 +#define MG_ALLLARGE 0x002 +static int memguard_options = MG_GUARD; +TUNABLE_INT("vm.memguard.options", &memguard_options); +SYSCTL_INT(_vm_memguard, OID_AUTO, options, CTLFLAG_RW, + &memguard_options, 0, + "MemGuard options:\n" + "\t0x001 - add guard pages around each allocation\n" + "\t0x002 - always use MemGuard for allocations over a page"); + +static u_int memguard_minsize; +static u_long memguard_minsize_reject; +SYSCTL_UINT(_vm_memguard, OID_AUTO, minsize, CTLFLAG_RW, + &memguard_minsize, 0, "Minimum size for page promotion"); +SYSCTL_ULONG(_vm_memguard, OID_AUTO, minsize_reject, CTLFLAG_RD, + &memguard_minsize_reject, 0, "# times rejected for size"); + +static u_int memguard_frequency; +static u_long memguard_frequency_hits; +TUNABLE_INT("vm.memguard.frequency", &memguard_frequency); +SYSCTL_UINT(_vm_memguard, OID_AUTO, frequency, CTLFLAG_RW, + &memguard_frequency, 0, "Times in 100000 that MemGuard will randomly run"); +SYSCTL_ULONG(_vm_memguard, OID_AUTO, frequency_hits, CTLFLAG_RD, + &memguard_frequency_hits, 0, "# times MemGuard randomly chose"); + + /* - * Global MemGuard data. + * Return a fudged value to be used for vm_kmem_size for allocating + * the kmem_map. The memguard memory will be a submap. */ -static vm_map_t memguard_map; -static unsigned long memguard_mapsize; -static unsigned long memguard_mapused; -struct memguard_entry { - STAILQ_ENTRY(memguard_entry) entries; - void *ptr; -}; -static struct memguard_fifo { - struct memguard_entry *stqh_first; - struct memguard_entry **stqh_last; - int index; -} memguard_fifo_pool[MAX_PAGES_PER_ITEM]; - -/* - * Local prototypes. - */ -static void memguard_guard(void *addr, int numpgs); -static void memguard_unguard(void *addr, int numpgs); -static struct memguard_fifo *vtomgfifo(vm_offset_t va); -static void vsetmgfifo(vm_offset_t va, struct memguard_fifo *mgfifo); -static void vclrmgfifo(vm_offset_t va); - -/* - * Local macros. MemGuard data is global, so replace these with whatever - * your system uses to protect global data (if it is kernel-level - * parallelized). This is for porting among BSDs. - */ -#define MEMGUARD_CRIT_SECTION_DECLARE static struct mtx memguard_mtx -#define MEMGUARD_CRIT_SECTION_INIT \ - mtx_init(&memguard_mtx, "MemGuard mtx", NULL, MTX_DEF) -#define MEMGUARD_CRIT_SECTION_ENTER mtx_lock(&memguard_mtx) -#define MEMGUARD_CRIT_SECTION_EXIT mtx_unlock(&memguard_mtx) -MEMGUARD_CRIT_SECTION_DECLARE; +unsigned long +memguard_fudge(unsigned long km_size, unsigned long km_max) +{ + u_long mem_pgs = cnt.v_page_count; + + vm_memguard_divisor = 10; + TUNABLE_INT_FETCH("vm.memguard.divisor", &vm_memguard_divisor); + + /* Pick a conservative value if provided value sucks. */ + if ((vm_memguard_divisor <= 0) || + ((km_size / vm_memguard_divisor) == 0)) + vm_memguard_divisor = 10; + /* + * Limit consumption of physical pages to + * 1/vm_memguard_divisor of system memory. If the KVA is + * smaller than this then the KVA limit comes into play first. + * This prevents memguard's page promotions from completely + * using up memory, since most malloc(9) calls are sub-page. + */ + memguard_physlimit = (mem_pgs / vm_memguard_divisor) * PAGE_SIZE; + /* + * We want as much KVA as we can take safely. Use at most our + * allotted fraction of kmem_max. Limit this to twice the + * physical memory to avoid using too much memory as pagetable + * pages. + */ + memguard_mapsize = km_max / vm_memguard_divisor; + /* size must be multiple of PAGE_SIZE */ + memguard_mapsize = round_page(memguard_mapsize); + if (memguard_mapsize / (2 * PAGE_SIZE) > mem_pgs) + memguard_mapsize = mem_pgs * 2 * PAGE_SIZE; + if (km_size + memguard_mapsize > km_max) + return (km_max); + return (km_size + memguard_mapsize); +} /* * Initialize the MemGuard mock allocator. All objects from MemGuard come * out of a single VM map (contiguous chunk of address space). */ void -memguard_init(vm_map_t parent_map, unsigned long size) +memguard_init(vm_map_t parent_map) { - char *base, *limit; - int i; - - /* size must be multiple of PAGE_SIZE */ - size /= PAGE_SIZE; - size++; - size *= PAGE_SIZE; + vm_offset_t base, limit; - memguard_map = kmem_suballoc(parent_map, (vm_offset_t *)&base, - (vm_offset_t *)&limit, (vm_size_t)size, FALSE); + memguard_map = kmem_suballoc(parent_map, &base, &limit, + memguard_mapsize, FALSE); memguard_map->system_map = 1; - memguard_mapsize = size; - memguard_mapused = 0; - - MEMGUARD_CRIT_SECTION_INIT; - MEMGUARD_CRIT_SECTION_ENTER; - for (i = 0; i < MAX_PAGES_PER_ITEM; i++) { - STAILQ_INIT(&memguard_fifo_pool[i]); - memguard_fifo_pool[i].index = i; - } - MEMGUARD_CRIT_SECTION_EXIT; + KASSERT(memguard_mapsize == limit - base, + ("Expected %lu, got %lu", (u_long)memguard_mapsize, + (u_long)(limit - base))); + memguard_cursor = base; printf("MEMGUARD DEBUGGING ALLOCATOR INITIALIZED:\n"); - printf("\tMEMGUARD map base: %p\n", base); - printf("\tMEMGUARD map limit: %p\n", limit); - printf("\tMEMGUARD map size: %ld (Bytes)\n", size); + printf("\tMEMGUARD map base: 0x%lx\n", (u_long)base); + printf("\tMEMGUARD map limit: 0x%lx\n", (u_long)limit); + printf("\tMEMGUARD map size: %jd KBytes\n", + (uintmax_t)memguard_mapsize >> 10); } /* - * Allocate a single object of specified size with specified flags (either - * M_WAITOK or M_NOWAIT). + * Run things that can't be done as early as memguard_init(). + */ +static void +memguard_sysinit(void) +{ + struct sysctl_oid_list *parent; + + parent = SYSCTL_STATIC_CHILDREN(_vm_memguard); + + SYSCTL_ADD_ULONG(NULL, parent, OID_AUTO, "mapstart", CTLFLAG_RD, + &memguard_map->min_offset, "MemGuard KVA base"); + SYSCTL_ADD_ULONG(NULL, parent, OID_AUTO, "maplimit", CTLFLAG_RD, + &memguard_map->max_offset, "MemGuard KVA end"); + SYSCTL_ADD_ULONG(NULL, parent, OID_AUTO, "mapused", CTLFLAG_RD, + &memguard_map->size, "MemGuard KVA used"); +} +SYSINIT(memguard, SI_SUB_KLD, SI_ORDER_ANY, memguard_sysinit, NULL); + +/* + * v2sizep() converts a virtual address of the first page allocated for + * an item to a pointer to u_long recording the size of the original + * allocation request. + * + * This routine is very similar to those defined by UMA in uma_int.h. + * The difference is that this routine stores the originally allocated + * size in one of the page's fields that is unused when the page is + * wired rather than the object field, which is used. + */ +static u_long * +v2sizep(vm_offset_t va) +{ + vm_paddr_t pa; + struct vm_page *p; + + pa = pmap_kextract(va); + if (pa == 0) + panic("MemGuard detected double-free of %p", (void *)va); + p = PHYS_TO_VM_PAGE(pa); + KASSERT(p->wire_count != 0 && p->queue == PQ_NONE, + ("MEMGUARD: Expected wired page %p in vtomgfifo!", p)); + return ((u_long *)&p->pageq.tqe_next); +} + +/* + * Allocate a single object of specified size with specified flags + * (either M_WAITOK or M_NOWAIT). */ void * -memguard_alloc(unsigned long size, int flags) +memguard_alloc(unsigned long req_size, int flags) { - void *obj; - struct memguard_entry *e = NULL; - int numpgs; - - numpgs = size / PAGE_SIZE; - if ((size % PAGE_SIZE) != 0) - numpgs++; - if (numpgs > MAX_PAGES_PER_ITEM) - panic("MEMGUARD: You must increase MAX_PAGES_PER_ITEM " \ - "in memguard.c (requested: %d pages)", numpgs); - if (numpgs == 0) - return NULL; - - /* - * If we haven't exhausted the memguard_map yet, allocate from - * it and grab a new page, even if we have recycled pages in our - * FIFO. This is because we wish to allow recycled pages to live - * guarded in the FIFO for as long as possible in order to catch - * even very late tamper-after-frees, even though it means that - * we end up wasting more memory, this is only a DEBUGGING allocator - * after all. - */ - MEMGUARD_CRIT_SECTION_ENTER; - if (memguard_mapused >= memguard_mapsize) { - e = STAILQ_FIRST(&memguard_fifo_pool[numpgs - 1]); - if (e != NULL) { - STAILQ_REMOVE(&memguard_fifo_pool[numpgs - 1], e, - memguard_entry, entries); - MEMGUARD_CRIT_SECTION_EXIT; - obj = e->ptr; - free(e, M_TEMP); - memguard_unguard(obj, numpgs); - if (flags & M_ZERO) - bzero(obj, PAGE_SIZE * numpgs); - return obj; + vm_offset_t addr; + u_long size_p, size_v; + int do_guard, rv; + + size_p = round_page(req_size); + if (size_p == 0) + return (NULL); + /* + * To ensure there are holes on both sides of the allocation, + * request 2 extra pages of KVA. We will only actually add a + * vm_map_entry and get pages for the original request. Save + * the value of memguard_options so we have a consistent + * value. + */ + size_v = size_p; + do_guard = (memguard_options & MG_GUARD) != 0; + if (do_guard) + size_v += 2 * PAGE_SIZE; + + vm_map_lock(memguard_map); + /* + * When we pass our memory limit, reject sub-page allocations. + * Page-size and larger allocations will use the same amount + * of physical memory whether we allocate or hand off to + * uma_large_alloc(), so keep those. + */ + if (memguard_map->size >= memguard_physlimit && + req_size < PAGE_SIZE) { + addr = (vm_offset_t)NULL; + memguard_fail_pgs++; + goto out; + } + /* + * Keep a moving cursor so we don't recycle KVA as long as + * possible. It's not perfect, since we don't know in what + * order previous allocations will be free'd, but it's simple + * and fast, and requires O(1) additional storage if guard + * pages are not used. + * + * XXX This scheme will lead to greater fragmentation of the + * map, unless vm_map_findspace() is tweaked. + */ + for (;;) { + rv = vm_map_findspace(memguard_map, memguard_cursor, + size_v, &addr); + if (rv == KERN_SUCCESS) + break; + /* + * The map has no space. This may be due to + * fragmentation, or because the cursor is near the + * end of the map. + */ + if (memguard_cursor == vm_map_min(memguard_map)) { + memguard_fail_kva++; + addr = (vm_offset_t)NULL; + goto out; } - MEMGUARD_CRIT_SECTION_EXIT; - if (flags & M_WAITOK) - panic("MEMGUARD: Failed with M_WAITOK: " \ - "memguard_map too small"); - return NULL; + memguard_wrap++; + memguard_cursor = vm_map_min(memguard_map); } - memguard_mapused += (PAGE_SIZE * numpgs); - MEMGUARD_CRIT_SECTION_EXIT; - - obj = (void *)kmem_malloc(memguard_map, PAGE_SIZE * numpgs, flags); - if (obj != NULL) { - vsetmgfifo((vm_offset_t)obj, &memguard_fifo_pool[numpgs - 1]); - if (flags & M_ZERO) - bzero(obj, PAGE_SIZE * numpgs); - } else { - MEMGUARD_CRIT_SECTION_ENTER; - memguard_mapused -= (PAGE_SIZE * numpgs); - MEMGUARD_CRIT_SECTION_EXIT; + if (do_guard) + addr += PAGE_SIZE; + rv = kmem_back(memguard_map, addr, size_p, flags); + if (rv != KERN_SUCCESS) { + memguard_fail_pgs++; + addr = (vm_offset_t)NULL; + goto out; } - return obj; + memguard_cursor = addr + size_p; + *v2sizep(trunc_page(addr)) = req_size; + memguard_succ++; + if (req_size < PAGE_SIZE) { + memguard_wasted += (PAGE_SIZE - req_size); + if (do_guard) { + /* + * Align the request to 16 bytes, and return + * an address near the end of the page, to + * better detect array overrun. + */ + req_size = roundup2(req_size, 16); + addr += (PAGE_SIZE - req_size); + } + } +out: + vm_map_unlock(memguard_map); + return ((void *)addr); +} + +int +is_memguard_addr(void *addr) +{ + vm_offset_t a = (vm_offset_t)(uintptr_t)addr; + + return (a >= memguard_map->min_offset && a < memguard_map->max_offset); } /* * Free specified single object. */ void -memguard_free(void *addr) +memguard_free(void *ptr) { - struct memguard_entry *e; - struct memguard_fifo *mgfifo; - int idx; - int *temp; - - addr = (void *)trunc_page((unsigned long)addr); - - /* - * Page should not be guarded by now, so force a write. - * The purpose of this is to increase the likelihood of catching a - * double-free, but not necessarily a tamper-after-free (the second - * thread freeing might not write before freeing, so this forces it - * to and, subsequently, trigger a fault). - */ - temp = (int *)((unsigned long)addr + (PAGE_SIZE/2)); /* in page */ - *temp = 0xd34dc0d3; - - mgfifo = vtomgfifo((vm_offset_t)addr); - idx = mgfifo->index; - memguard_guard(addr, idx + 1); - e = malloc(sizeof(struct memguard_entry), M_TEMP, M_NOWAIT); - if (e == NULL) { - MEMGUARD_CRIT_SECTION_ENTER; - memguard_mapused -= (PAGE_SIZE * (idx + 1)); - MEMGUARD_CRIT_SECTION_EXIT; - memguard_unguard(addr, idx + 1); /* just in case */ - vclrmgfifo((vm_offset_t)addr); - kmem_free(memguard_map, (vm_offset_t)addr, - PAGE_SIZE * (idx + 1)); - return; - } - e->ptr = addr; - MEMGUARD_CRIT_SECTION_ENTER; - STAILQ_INSERT_TAIL(mgfifo, e, entries); - MEMGUARD_CRIT_SECTION_EXIT; + vm_offset_t addr; + u_long req_size, size; + char *temp; + int i; + + addr = trunc_page((uintptr_t)ptr); + req_size = *v2sizep(addr); + size = round_page(req_size); + + /* + * Page should not be guarded right now, so force a write. + * The purpose of this is to increase the likelihood of + * catching a double-free, but not necessarily a + * tamper-after-free (the second thread freeing might not + * write before freeing, so this forces it to and, + * subsequently, trigger a fault). + */ + temp = ptr; + for (i = 0; i < size; i += PAGE_SIZE) + temp[i] = 'M'; + + /* + * This requires carnal knowledge of the implementation of + * kmem_free(), but since we've already replaced kmem_malloc() + * above, it's not really any worse. We want to use the + * vm_map lock to serialize updates to memguard_wasted, since + * we had the lock at increment. + */ + vm_map_lock(memguard_map); + if (req_size < PAGE_SIZE) + memguard_wasted -= (PAGE_SIZE - req_size); + (void)vm_map_delete(memguard_map, addr, addr + size); + vm_map_unlock(memguard_map); +} + +/* + * Re-allocate an allocation that was originally guarded. + */ +void * +memguard_realloc(void *addr, unsigned long size, struct malloc_type *mtp, + int flags) +{ + void *newaddr; + u_long old_size; + + /* + * Allocate the new block. Force the allocation to be guarded + * as the original may have been guarded through random + * chance, and that should be preserved. + */ + if ((newaddr = memguard_alloc(size, flags)) == NULL) + return (NULL); + + /* Copy over original contents. */ + old_size = *v2sizep(trunc_page((uintptr_t)addr)); + bcopy(addr, newaddr, min(size, old_size)); + memguard_free(addr); + return (newaddr); } int -memguard_cmp(struct malloc_type *mtp) +memguard_cmp(struct malloc_type *mtp, unsigned long size) { + if (size < memguard_minsize) { + memguard_minsize_reject++; + return (0); + } + if ((memguard_options & MG_ALLLARGE) != 0 && size >= PAGE_SIZE) + return (1); + if (memguard_frequency > 0 && + (random() % 100000) < memguard_frequency) { + memguard_frequency_hits++; + return (1); + } #if 1 /* * The safest way of comparsion is to always compare short description @@ -328,78 +466,3 @@ memguard_cmp(struct malloc_type *mtp) return (0); #endif } - -/* - * Guard a page containing specified object (make it read-only so that - * future writes to it fail). - */ -static void -memguard_guard(void *addr, int numpgs) -{ - void *a = (void *)trunc_page((unsigned long)addr); - if (vm_map_protect(memguard_map, (vm_offset_t)a, - (vm_offset_t)((unsigned long)a + (PAGE_SIZE * numpgs)), - VM_PROT_READ, FALSE) != KERN_SUCCESS) - panic("MEMGUARD: Unable to guard page!"); -} - -/* - * Unguard a page containing specified object (make it read-and-write to - * allow full data access). - */ -static void -memguard_unguard(void *addr, int numpgs) -{ - void *a = (void *)trunc_page((unsigned long)addr); - if (vm_map_protect(memguard_map, (vm_offset_t)a, - (vm_offset_t)((unsigned long)a + (PAGE_SIZE * numpgs)), - VM_PROT_DEFAULT, FALSE) != KERN_SUCCESS) - panic("MEMGUARD: Unable to unguard page!"); -} - -/* - * vtomgfifo() converts a virtual address of the first page allocated for - * an item to a memguard_fifo_pool reference for the corresponding item's - * size. - * - * vsetmgfifo() sets a reference in an underlying page for the specified - * virtual address to an appropriate memguard_fifo_pool. - * - * These routines are very similar to those defined by UMA in uma_int.h. - * The difference is that these routines store the mgfifo in one of the - * page's fields that is unused when the page is wired rather than the - * object field, which is used. - */ -static struct memguard_fifo * -vtomgfifo(vm_offset_t va) -{ - vm_page_t p; - struct memguard_fifo *mgfifo; - - p = PHYS_TO_VM_PAGE(pmap_kextract(va)); - KASSERT(p->wire_count != 0 && p->queue == PQ_NONE, - ("MEMGUARD: Expected wired page in vtomgfifo!")); - mgfifo = (struct memguard_fifo *)p->pageq.tqe_next; - return mgfifo; -} - -static void -vsetmgfifo(vm_offset_t va, struct memguard_fifo *mgfifo) -{ - vm_page_t p; - - p = PHYS_TO_VM_PAGE(pmap_kextract(va)); - KASSERT(p->wire_count != 0 && p->queue == PQ_NONE, - ("MEMGUARD: Expected wired page in vsetmgfifo!")); - p->pageq.tqe_next = (vm_page_t)mgfifo; -} - -static void vclrmgfifo(vm_offset_t va) -{ - vm_page_t p; - - p = PHYS_TO_VM_PAGE(pmap_kextract(va)); - KASSERT(p->wire_count != 0 && p->queue == PQ_NONE, - ("MEMGUARD: Expected wired page in vclrmgfifo!")); - p->pageq.tqe_next = NULL; -} Modified: stable/7/sys/vm/memguard.h ============================================================================== --- stable/7/sys/vm/memguard.h Fri Sep 10 21:45:42 2010 (r212436) +++ stable/7/sys/vm/memguard.h Fri Sep 10 21:53:47 2010 (r212437) @@ -26,9 +26,30 @@ * $FreeBSD$ */ -extern u_int vm_memguard_divisor; +#ifndef _VM_MEMGUARD_H_ +#define _VM_MEMGUARD_H_ -void memguard_init(vm_map_t parent_map, unsigned long size); -void *memguard_alloc(unsigned long size, int flags); -void memguard_free(void *addr); -int memguard_cmp(struct malloc_type *mtp); +#include "opt_vm.h" + +struct malloc_type; +struct vm_map; + +#ifdef DEBUG_MEMGUARD +unsigned long memguard_fudge(unsigned long, unsigned long); +void memguard_init(struct vm_map *); +void *memguard_alloc(unsigned long, int); +void *memguard_realloc(void *, unsigned long, struct malloc_type *, int); +void memguard_free(void *); +int memguard_cmp(struct malloc_type *, unsigned long); +int is_memguard_addr(void *); +#else +#define memguard_fudge(size, xxx) (size) +#define memguard_init(map) do { } while (0) +#define memguard_alloc(size, flags) NULL +#define memguard_realloc(a, s, mtp, f) NULL +#define memguard_free(addr) do { } while (0) +#define memguard_cmp(mtp, size) 0 +#define is_memguard_addr(addr) 0 +#endif + +#endif /* _VM_MEMGUARD_H_ */ Modified: stable/7/sys/vm/vm_extern.h ============================================================================== --- stable/7/sys/vm/vm_extern.h Fri Sep 10 21:45:42 2010 (r212436) +++ stable/7/sys/vm/vm_extern.h Fri Sep 10 21:53:47 2010 (r212437) @@ -68,6 +68,7 @@ void kmem_free(vm_map_t, vm_offset_t, vm void kmem_free_wakeup(vm_map_t, vm_offset_t, vm_size_t); void kmem_init(vm_offset_t, vm_offset_t); vm_offset_t kmem_malloc(vm_map_t map, vm_size_t size, int flags); +int kmem_back(vm_map_t, vm_offset_t, vm_size_t, int); vm_map_t kmem_suballoc(vm_map_t, vm_offset_t *, vm_offset_t *, vm_size_t, boolean_t); void swapout_procs(int); Modified: stable/7/sys/vm/vm_kern.c ============================================================================== --- stable/7/sys/vm/vm_kern.c Fri Sep 10 21:45:42 2010 (r212436) +++ stable/7/sys/vm/vm_kern.c Fri Sep 10 21:53:47 2010 (r212437) @@ -272,11 +272,8 @@ kmem_malloc(map, size, flags) vm_size_t size; int flags; { - vm_offset_t offset, i; - vm_map_entry_t entry; vm_offset_t addr; - vm_page_t m; - int pflags; + int i, rv; size = round_page(size); *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-stable@FreeBSD.ORG Sat Sep 11 01:08:16 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 86ADE106566B; Sat, 11 Sep 2010 01:08:16 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 74DF98FC16; Sat, 11 Sep 2010 01:08:16 +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 o8B18GdF008423; Sat, 11 Sep 2010 01:08:16 GMT (envelope-from rmacklem@svn.freebsd.org) Received: (from rmacklem@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o8B18Ghx008418; Sat, 11 Sep 2010 01:08:16 GMT (envelope-from rmacklem@svn.freebsd.org) Message-Id: <201009110108.o8B18Ghx008418@svn.freebsd.org> From: Rick Macklem Date: Sat, 11 Sep 2010 01:08:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212446 - in stable/8/sys/fs: nfs nfsserver X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Sep 2010 01:08:16 -0000 Author: rmacklem Date: Sat Sep 11 01:08:16 2010 New Revision: 212446 URL: http://svn.freebsd.org/changeset/base/212446 Log: MFC: r211951 The timer routine in the experimental NFS server did not acquire the correct mutex when checking nfsv4root_lock. Although this could be fixed by adding mutex lock/unlock calls, zack.kirsch at isilon.com suggested a better fix that uses a non-blocking acquisition of a reference count on nfsv4root_lock. This fix allows the weird NFSLOCKSTATE(); NFSUNLOCKSTATE(); synchronization to be deleted. This patch applies this fix. Modified: stable/8/sys/fs/nfs/nfs_commonsubs.c stable/8/sys/fs/nfs/nfs_var.h stable/8/sys/fs/nfsserver/nfs_nfsdsocket.c stable/8/sys/fs/nfsserver/nfs_nfsdstate.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/fs/nfs/nfs_commonsubs.c ============================================================================== --- stable/8/sys/fs/nfs/nfs_commonsubs.c Fri Sep 10 23:55:46 2010 (r212445) +++ stable/8/sys/fs/nfs/nfs_commonsubs.c Sat Sep 11 01:08:16 2010 (r212446) @@ -1835,6 +1835,21 @@ nfsv4_getref(struct nfsv4lock *lp, int * } /* + * Get a reference as above, but return failure instead of sleeping if + * an exclusive lock is held. + */ +APPLESTATIC int +nfsv4_getref_nonblock(struct nfsv4lock *lp) +{ + + if ((lp->nfslock_lock & NFSV4LOCK_LOCK) != 0) + return (0); + + lp->nfslock_usecnt++; + return (1); +} + +/* * Test for a lock. Return 1 if locked, 0 otherwise. */ APPLESTATIC int Modified: stable/8/sys/fs/nfs/nfs_var.h ============================================================================== --- stable/8/sys/fs/nfs/nfs_var.h Fri Sep 10 23:55:46 2010 (r212445) +++ stable/8/sys/fs/nfs/nfs_var.h Sat Sep 11 01:08:16 2010 (r212446) @@ -251,6 +251,7 @@ int nfsv4_lock(struct nfsv4lock *, int, void nfsv4_unlock(struct nfsv4lock *, int); void nfsv4_relref(struct nfsv4lock *); void nfsv4_getref(struct nfsv4lock *, int *, void *); +int nfsv4_getref_nonblock(struct nfsv4lock *); int nfsv4_testlock(struct nfsv4lock *); int nfsrv_mtostr(struct nfsrv_descript *, char *, int); int nfsrv_checkutf8(u_int8_t *, int); Modified: stable/8/sys/fs/nfsserver/nfs_nfsdsocket.c ============================================================================== --- stable/8/sys/fs/nfsserver/nfs_nfsdsocket.c Fri Sep 10 23:55:46 2010 (r212445) +++ stable/8/sys/fs/nfsserver/nfs_nfsdsocket.c Sat Sep 11 01:08:16 2010 (r212446) @@ -533,8 +533,6 @@ nfsrvd_compound(struct nfsrv_descript *n NFSV4ROOTLOCKMUTEXPTR); NFSUNLOCKV4ROOTMUTEX(); if (igotlock) { - NFSLOCKSTATE(); /* to avoid a race with */ - NFSUNLOCKSTATE(); /* nfsrv_servertimer() */ /* * If I got the lock, I can update the stable storage file. * Done when the grace period is over or a client has long Modified: stable/8/sys/fs/nfsserver/nfs_nfsdstate.c ============================================================================== --- stable/8/sys/fs/nfsserver/nfs_nfsdstate.c Fri Sep 10 23:55:46 2010 (r212445) +++ stable/8/sys/fs/nfsserver/nfs_nfsdstate.c Sat Sep 11 01:08:16 2010 (r212446) @@ -164,8 +164,6 @@ nfsrv_setclient(struct nfsrv_descript *n NFSV4ROOTLOCKMUTEXPTR); } while (!igotlock); NFSUNLOCKV4ROOTMUTEX(); - NFSLOCKSTATE(); /* to avoid a race with */ - NFSUNLOCKSTATE(); /* nfsrv_servertimer() */ /* * Search for a match in the client list. @@ -416,8 +414,6 @@ nfsrv_getclient(nfsquad_t clientid, int NFSV4ROOTLOCKMUTEXPTR); } while (!igotlock); NFSUNLOCKV4ROOTMUTEX(); - NFSLOCKSTATE(); /* to avoid a race with */ - NFSUNLOCKSTATE(); /* nfsrv_servertimer() */ } else if (opflags != CLOPS_RENEW) { NFSLOCKSTATE(); } @@ -547,8 +543,6 @@ nfsrv_adminrevoke(struct nfsd_clid *revo NFSV4ROOTLOCKMUTEXPTR); } while (!igotlock); NFSUNLOCKV4ROOTMUTEX(); - NFSLOCKSTATE(); /* to avoid a race with */ - NFSUNLOCKSTATE(); /* nfsrv_servertimer() */ /* * Search for a match in the client list. @@ -824,11 +818,8 @@ nfsrv_dumplocks(vnode_t vp, struct nfsd_ /* * Server timer routine. It can scan any linked list, so long - * as it holds the spin lock and there is no exclusive lock on + * as it holds the spin/mutex lock and there is no exclusive lock on * nfsv4rootfs_lock. - * Must be called by a kernel thread and not a timer interrupt, - * so that it only runs when the nfsd threads are sleeping on a - * uniprocessor and uses the State spin lock for an SMP system. * (For OpenBSD, a kthread is ok. For FreeBSD, I think it is ok * to do this from a callout, since the spin locks work. For * Darwin, I'm not sure what will work correctly yet.) @@ -839,7 +830,7 @@ nfsrv_servertimer(void) { struct nfsclient *clp, *nclp; struct nfsstate *stp, *nstp; - int i; + int got_ref, i; /* * Make sure nfsboottime is set. This is used by V3 as well @@ -867,13 +858,14 @@ nfsrv_servertimer(void) } /* - * Return now if an nfsd thread has the exclusive lock on - * nfsv4rootfs_lock. The dirty trick here is that we have - * the spin lock already and the nfsd threads do a: - * NFSLOCKSTATE, NFSUNLOCKSTATE after getting the exclusive - * lock, so they won't race with code after this check. + * Try and get a reference count on the nfsv4rootfs_lock so that + * no nfsd thread can acquire an exclusive lock on it before this + * call is done. If it is already exclusively locked, just return. */ - if (nfsv4rootfs_lock.nfslock_lock & NFSV4LOCK_LOCK) { + NFSLOCKV4ROOTMUTEX(); + got_ref = nfsv4_getref_nonblock(&nfsv4rootfs_lock); + NFSUNLOCKV4ROOTMUTEX(); + if (got_ref == 0) { NFSUNLOCKSTATE(); return; } @@ -945,6 +937,9 @@ nfsrv_servertimer(void) } } NFSUNLOCKSTATE(); + NFSLOCKV4ROOTMUTEX(); + nfsv4_relref(&nfsv4rootfs_lock); + NFSUNLOCKV4ROOTMUTEX(); } /* @@ -4224,8 +4219,6 @@ nfsrv_clientconflict(struct nfsclient *c NFSV4ROOTLOCKMUTEXPTR); } while (!gotlock); NFSUNLOCKV4ROOTMUTEX(); - NFSLOCKSTATE(); /* to avoid a race with */ - NFSUNLOCKSTATE(); /* nfsrv_servertimer() */ *haslockp = 1; NFSVOPLOCK(vp, LK_EXCLUSIVE | LK_RETRY, p); return (1); @@ -4390,8 +4383,6 @@ nfsrv_delegconflict(struct nfsstate *stp NFSV4ROOTLOCKMUTEXPTR); } while (!gotlock); NFSUNLOCKV4ROOTMUTEX(); - NFSLOCKSTATE(); /* to avoid a race with */ - NFSUNLOCKSTATE(); /* nfsrv_servertimer() */ *haslockp = 1; NFSVOPLOCK(vp, LK_EXCLUSIVE | LK_RETRY, p); return (-1); From owner-svn-src-stable@FreeBSD.ORG Sat Sep 11 02:00:28 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1642B106566C; Sat, 11 Sep 2010 02:00:28 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 0567B8FC0A; Sat, 11 Sep 2010 02:00:28 +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 o8B20Rjj016730; Sat, 11 Sep 2010 02:00:27 GMT (envelope-from rmacklem@svn.freebsd.org) Received: (from rmacklem@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o8B20R66016728; Sat, 11 Sep 2010 02:00:27 GMT (envelope-from rmacklem@svn.freebsd.org) Message-Id: <201009110200.o8B20R66016728@svn.freebsd.org> From: Rick Macklem Date: Sat, 11 Sep 2010 02:00:27 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212452 - stable/8/sys/fs/nfsserver X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Sep 2010 02:00:28 -0000 Author: rmacklem Date: Sat Sep 11 02:00:27 2010 New Revision: 212452 URL: http://svn.freebsd.org/changeset/base/212452 Log: MFC: r211953 Add acquisition of a reference count on nfsv4root_lock in the nfsd_recalldelegation() function, since this function is called by nfsd threads when they are handling NFSv2 or NFSv3 RPCs, where no reference count would have been acquired. Modified: stable/8/sys/fs/nfsserver/nfs_nfsdstate.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/fs/nfsserver/nfs_nfsdstate.c ============================================================================== --- stable/8/sys/fs/nfsserver/nfs_nfsdstate.c Sat Sep 11 01:51:45 2010 (r212451) +++ stable/8/sys/fs/nfsserver/nfs_nfsdstate.c Sat Sep 11 02:00:27 2010 (r212452) @@ -4563,6 +4563,14 @@ nfsd_recalldelegation(vnode_t vp, NFSPRO return; /* + * First, get a reference on the nfsv4rootfs_lock so that an + * exclusive lock cannot be acquired by another thread. + */ + NFSLOCKV4ROOTMUTEX(); + nfsv4_getref(&nfsv4rootfs_lock, NULL, NFSV4ROOTLOCKMUTEXPTR); + NFSUNLOCKV4ROOTMUTEX(); + + /* * Now, call nfsrv_checkremove() in a loop while it returns * NFSERR_DELAY. Return upon any other error or when timed out. */ @@ -4576,11 +4584,14 @@ nfsd_recalldelegation(vnode_t vp, NFSPRO NFS_REMOVETIMEO && ((u_int32_t)mytime.tv_sec - starttime) < 100000) - return; + break; /* Sleep for a short period of time */ (void) nfs_catnap(PZERO, 0, "nfsremove"); } } while (error == NFSERR_DELAY); + NFSLOCKV4ROOTMUTEX(); + nfsv4_relref(&nfsv4rootfs_lock); + NFSUNLOCKV4ROOTMUTEX(); } APPLESTATIC void From owner-svn-src-stable@FreeBSD.ORG Sat Sep 11 06:38:34 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A4DF1106566B; Sat, 11 Sep 2010 06:38:34 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 883508FC15; Sat, 11 Sep 2010 06:38:34 +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 o8B6cYoJ056608; Sat, 11 Sep 2010 06:38:34 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o8B6cYxn056606; Sat, 11 Sep 2010 06:38:34 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201009110638.o8B6cYxn056606@svn.freebsd.org> From: Konstantin Belousov Date: Sat, 11 Sep 2010 06:38:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212454 - stable/8/tools/regression/poll X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Sep 2010 06:38:34 -0000 Author: kib Date: Sat Sep 11 06:38:34 2010 New Revision: 212454 URL: http://svn.freebsd.org/changeset/base/212454 Log: MFC r211940: Test the poll(2) return value. Modified: stable/8/tools/regression/poll/pipepoll.c Directory Properties: stable/8/tools/regression/poll/ (props changed) Modified: stable/8/tools/regression/poll/pipepoll.c ============================================================================== --- stable/8/tools/regression/poll/pipepoll.c Sat Sep 11 04:45:51 2010 (r212453) +++ stable/8/tools/regression/poll/pipepoll.c Sat Sep 11 06:38:34 2010 (r212454) @@ -44,16 +44,34 @@ decode_events(int events) } static void -report(int num, const char *state, int expected, int got) +report_state(const char *state) { - if (expected == got) - printf("ok %-2d ", num); - else - printf("not ok %-2d", num); - printf(" %s state %s: expected %s; got %s\n", + + printf(" %s state %s: ", filetype == FT_PIPE ? "Pipe" : filetype == FT_SOCKETPAIR ? "Sock" : "FIFO", - state, decode_events(expected), decode_events(got)); + state); +} + +static void +report(int num, const char *state, int expected, int got, int res, + int res_expected) +{ + + if (res != res_expected) { + printf("not ok %-2d", num); + report_state(state); + printf("poll result %d expected %d. ", + res, res_expected); + } else { + if (expected == got) + printf("ok %-2d ", num); + else + printf("not ok %-2d", num); + report_state(state); + } + printf("expected %s; got %s\n", decode_events(expected), + decode_events(got)); fflush(stdout); } @@ -62,8 +80,9 @@ static pid_t ppid; static volatile sig_atomic_t state; static void -catch(int sig) +catch(int sig __unused) { + state++; } @@ -71,7 +90,7 @@ static void child(int fd, int num) { struct pollfd pfd; - int fd2; + int fd2, res; char buf[256]; if (filetype == FT_FIFO) { @@ -83,9 +102,9 @@ child(int fd, int num) pfd.events = POLLIN; if (filetype == FT_FIFO) { - if (poll(&pfd, 1, 0) < 0) + if ((res = poll(&pfd, 1, 0)) < 0) err(1, "poll"); - report(num++, "0", 0, pfd.revents); + report(num++, "0", 0, pfd.revents, res, 0); } kill(ppid, SIGUSR1); @@ -101,30 +120,30 @@ child(int fd, int num) state = 4; goto state4; } - if (poll(&pfd, 1, 0) < 0) + if ((res = poll(&pfd, 1, 0)) < 0) err(1, "poll"); - report(num++, "1", 0, pfd.revents); + report(num++, "1", 0, pfd.revents, res, 0); kill(ppid, SIGUSR1); usleep(1); while (state != 2) ; - if (poll(&pfd, 1, 0) < 0) + if ((res = poll(&pfd, 1, 0)) < 0) err(1, "poll"); - report(num++, "2", POLLIN, pfd.revents); + report(num++, "2", POLLIN, pfd.revents, res, 1); if (read(fd, buf, sizeof buf) != 1) err(1, "read"); - if (poll(&pfd, 1, 0) < 0) + if ((res = poll(&pfd, 1, 0)) < 0) err(1, "poll"); - report(num++, "2a", 0, pfd.revents); + report(num++, "2a", 0, pfd.revents, res, 0); kill(ppid, SIGUSR1); usleep(1); while (state != 3) ; - if (poll(&pfd, 1, 0) < 0) + if ((res = poll(&pfd, 1, 0)) < 0) err(1, "poll"); - report(num++, "3", POLLHUP, pfd.revents); + report(num++, "3", POLLHUP, pfd.revents, res, 1); kill(ppid, SIGUSR1); /* @@ -137,17 +156,17 @@ child(int fd, int num) while (state != 4) ; state4: - if (poll(&pfd, 1, 0) < 0) + if ((res = poll(&pfd, 1, 0)) < 0) err(1, "poll"); - report(num++, "4", 0, pfd.revents); + report(num++, "4", 0, pfd.revents, res, 0); kill(ppid, SIGUSR1); usleep(1); while (state != 5) ; - if (poll(&pfd, 1, 0) < 0) + if ((res = poll(&pfd, 1, 0)) < 0) err(1, "poll"); - report(num++, "5", POLLIN, pfd.revents); + report(num++, "5", POLLIN, pfd.revents, res, 1); kill(ppid, SIGUSR1); usleep(1); @@ -163,14 +182,14 @@ state4: * is an example of a broken program that quits on POLLHUP only -- * see its event-loop.c. */ - if (poll(&pfd, 1, 0) < 0) + if ((res = poll(&pfd, 1, 0)) < 0) err(1, "poll"); - report(num++, "6", POLLIN | POLLHUP, pfd.revents); + report(num++, "6", POLLIN | POLLHUP, pfd.revents, res, 1); if (read(fd, buf, sizeof buf) != 1) err(1, "read"); - if (poll(&pfd, 1, 0) < 0) + if ((res = poll(&pfd, 1, 0)) < 0) err(1, "poll"); - report(num++, "6a", POLLHUP, pfd.revents); + report(num++, "6a", POLLHUP, pfd.revents, res, 1); if (filetype == FT_FIFO) { /* * Check that POLLHUP is sticky for a new reader and for @@ -180,17 +199,17 @@ state4: if (fd2 < 0) err(1, "open for read"); pfd.fd = fd2; - if (poll(&pfd, 1, 0) < 0) + if ((res = poll(&pfd, 1, 0)) < 0) err(1, "poll"); - report(num++, "6b", POLLHUP, pfd.revents); + report(num++, "6b", POLLHUP, pfd.revents, res, 1); pfd.fd = fd; - if (poll(&pfd, 1, 0) < 0) + if ((res = poll(&pfd, 1, 0)) < 0) err(1, "poll"); - report(num++, "6c", POLLHUP, pfd.revents); + report(num++, "6c", POLLHUP, pfd.revents, res, 1); close(fd2); - if (poll(&pfd, 1, 0) < 0) + if ((res = poll(&pfd, 1, 0)) < 0) err(1, "poll"); - report(num++, "6d", POLLHUP, pfd.revents); + report(num++, "6d", POLLHUP, pfd.revents, res, 1); } close(fd); kill(ppid, SIGUSR1); From owner-svn-src-stable@FreeBSD.ORG Sat Sep 11 12:51:01 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C78D51065674; Sat, 11 Sep 2010 12:51:01 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id B6BA58FC1A; Sat, 11 Sep 2010 12:51:01 +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 o8BCp1cf096743; Sat, 11 Sep 2010 12:51:01 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o8BCp1Wr096741; Sat, 11 Sep 2010 12:51:01 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201009111251.o8BCp1Wr096741@svn.freebsd.org> From: Jilles Tjoelker Date: Sat, 11 Sep 2010 12:51:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212464 - stable/8/bin/sh X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Sep 2010 12:51:01 -0000 Author: jilles Date: Sat Sep 11 12:51:01 2010 New Revision: 212464 URL: http://svn.freebsd.org/changeset/base/212464 Log: MFC r212214: sh: Get rid of some magic numbers. Modified: stable/8/bin/sh/eval.c Directory Properties: stable/8/bin/sh/ (props changed) Modified: stable/8/bin/sh/eval.c ============================================================================== --- stable/8/bin/sh/eval.c Sat Sep 11 10:49:56 2010 (r212463) +++ stable/8/bin/sh/eval.c Sat Sep 11 12:51:01 2010 (r212464) @@ -896,7 +896,7 @@ cmddone: goto out; parent: /* parent process gets here (if we forked) */ - if (mode == 0) { /* argument to fork */ + if (mode == FORK_FG) { /* argument to fork */ INTOFF; exitstatus = waitforjob(jp, &realstatus); INTON; @@ -904,7 +904,7 @@ parent: /* parent process gets here (if evalskip = SKIPBREAK; skipcount = loopnest; } - } else if (mode == 2) { + } else if (mode == FORK_NOJOB) { backcmd->fd = pip[0]; close(pip[1]); backcmd->jp = jp; From owner-svn-src-stable@FreeBSD.ORG Sat Sep 11 14:18:31 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8BEEA1065672; Sat, 11 Sep 2010 14:18:31 +0000 (UTC) (envelope-from brucec@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 60B808FC17; Sat, 11 Sep 2010 14:18:31 +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 o8BEIV9R004300; Sat, 11 Sep 2010 14:18:31 GMT (envelope-from brucec@svn.freebsd.org) Received: (from brucec@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o8BEIVtC004299; Sat, 11 Sep 2010 14:18:31 GMT (envelope-from brucec@svn.freebsd.org) Message-Id: <201009111418.o8BEIVtC004299@svn.freebsd.org> From: Bruce Cran Date: Sat, 11 Sep 2010 14:18:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212468 - stable/8/sys/dev/sis X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Sep 2010 14:18:31 -0000 Author: brucec Date: Sat Sep 11 14:18:30 2010 New Revision: 212468 URL: http://svn.freebsd.org/changeset/base/212468 Log: MFC r206909: It's not necessary to reset the chip every time an input overflow event occurs. In addition, the delay when programming the short cable fix should be 100us, not 100ms. PR: kern/64556 Approved by: rrs (mentor) Modified: stable/8/sys/dev/sis/if_sis.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/dev/sis/if_sis.c ============================================================================== --- stable/8/sys/dev/sis/if_sis.c Sat Sep 11 14:15:50 2010 (r212467) +++ stable/8/sys/dev/sis/if_sis.c Sat Sep 11 14:18:30 2010 (r212468) @@ -1483,15 +1483,6 @@ sis_rxeof(struct sis_softc *sc) return (rx_npkts); } -static void -sis_rxeoc(struct sis_softc *sc) -{ - - SIS_LOCK_ASSERT(sc); - sis_rxeof(sc); - sis_initl(sc); -} - /* * A frame was downloaded to the chip. It's safe for us to clean up * the list buffers. @@ -1614,7 +1605,7 @@ sis_poll(struct ifnet *ifp, enum poll_cm status = CSR_READ_4(sc, SIS_ISR); if (status & (SIS_ISR_RX_ERR|SIS_ISR_RX_OFLOW)) - sis_rxeoc(sc); + ifp->if_ierrors++; if (status & (SIS_ISR_RX_IDLE)) SIS_SETBIT(sc, SIS_CSR, SIS_CSR_RX_ENABLE); @@ -1672,7 +1663,7 @@ sis_intr(void *arg) sis_rxeof(sc); if (status & SIS_ISR_RX_OFLOW) - sis_rxeoc(sc); + ifp->if_ierrors++; if (status & (SIS_ISR_RX_IDLE)) SIS_SETBIT(sc, SIS_CSR, SIS_CSR_RX_ENABLE); @@ -2017,7 +2008,7 @@ sis_initl(struct sis_softc *sc) CSR_WRITE_4(sc, NS_PHY_PAGE, 0x0001); reg = CSR_READ_4(sc, NS_PHY_DSPCFG) & 0xfff; CSR_WRITE_4(sc, NS_PHY_DSPCFG, reg | 0x1000); - DELAY(100000); + DELAY(100); reg = CSR_READ_4(sc, NS_PHY_TDATA) & 0xff; if ((reg & 0x0080) == 0 || (reg > 0xd8 && reg <= 0xff)) { device_printf(sc->sis_dev, From owner-svn-src-stable@FreeBSD.ORG Sat Sep 11 14:21:03 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5402D106566B; Sat, 11 Sep 2010 14:21:03 +0000 (UTC) (envelope-from brucec@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 2885C8FC17; Sat, 11 Sep 2010 14:21:03 +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 o8BEL31m004494; Sat, 11 Sep 2010 14:21:03 GMT (envelope-from brucec@svn.freebsd.org) Received: (from brucec@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o8BEL3bc004492; Sat, 11 Sep 2010 14:21:03 GMT (envelope-from brucec@svn.freebsd.org) Message-Id: <201009111421.o8BEL3bc004492@svn.freebsd.org> From: Bruce Cran Date: Sat, 11 Sep 2010 14:21:03 +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: r212469 - stable/7/sys/dev/sis X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Sep 2010 14:21:03 -0000 Author: brucec Date: Sat Sep 11 14:21:02 2010 New Revision: 212469 URL: http://svn.freebsd.org/changeset/base/212469 Log: MFC r206909: It's not necessary to reset the chip every time an input overflow event occurs. In addition, the delay when programming the short cable fix should be 100us, not 100ms. PR: kern/64556 Submitted by: Thomas Hurst Approved by: rrs (mentor) Modified: stable/7/sys/dev/sis/if_sis.c 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/dev/sis/if_sis.c ============================================================================== --- stable/7/sys/dev/sis/if_sis.c Sat Sep 11 14:18:30 2010 (r212468) +++ stable/7/sys/dev/sis/if_sis.c Sat Sep 11 14:21:02 2010 (r212469) @@ -1480,15 +1480,6 @@ sis_rxeof(struct sis_softc *sc) sc->sis_rx_pdsc = cur_rx; } -static void -sis_rxeoc(struct sis_softc *sc) -{ - - SIS_LOCK_ASSERT(sc); - sis_rxeof(sc); - sis_initl(sc); -} - /* * A frame was downloaded to the chip. It's safe for us to clean up * the list buffers. @@ -1610,7 +1601,7 @@ sis_poll(struct ifnet *ifp, enum poll_cm status = CSR_READ_4(sc, SIS_ISR); if (status & (SIS_ISR_RX_ERR|SIS_ISR_RX_OFLOW)) - sis_rxeoc(sc); + ifp->if_ierrors++; if (status & (SIS_ISR_RX_IDLE)) SIS_SETBIT(sc, SIS_CSR, SIS_CSR_RX_ENABLE); @@ -1667,7 +1658,7 @@ sis_intr(void *arg) sis_rxeof(sc); if (status & SIS_ISR_RX_OFLOW) - sis_rxeoc(sc); + ifp->if_ierrors++; if (status & (SIS_ISR_RX_IDLE)) SIS_SETBIT(sc, SIS_CSR, SIS_CSR_RX_ENABLE); @@ -2012,7 +2003,7 @@ sis_initl(struct sis_softc *sc) CSR_WRITE_4(sc, NS_PHY_PAGE, 0x0001); reg = CSR_READ_4(sc, NS_PHY_DSPCFG) & 0xfff; CSR_WRITE_4(sc, NS_PHY_DSPCFG, reg | 0x1000); - DELAY(100000); + DELAY(100); reg = CSR_READ_4(sc, NS_PHY_TDATA) & 0xff; if ((reg & 0x0080) == 0 || (reg > 0xd8 && reg <= 0xff)) { device_printf(sc->sis_dev, From owner-svn-src-stable@FreeBSD.ORG Sat Sep 11 14:26:18 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E5F1F10656C1; Sat, 11 Sep 2010 14:26:18 +0000 (UTC) (envelope-from brucec@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D52778FC17; Sat, 11 Sep 2010 14:26:18 +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 o8BEQIXJ004851; Sat, 11 Sep 2010 14:26:18 GMT (envelope-from brucec@svn.freebsd.org) Received: (from brucec@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o8BEQINf004849; Sat, 11 Sep 2010 14:26:18 GMT (envelope-from brucec@svn.freebsd.org) Message-Id: <201009111426.o8BEQINf004849@svn.freebsd.org> From: Bruce Cran Date: Sat, 11 Sep 2010 14:26:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212470 - stable/8/contrib/top X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Sep 2010 14:26:19 -0000 Author: brucec Date: Sat Sep 11 14:26:18 2010 New Revision: 212470 URL: http://svn.freebsd.org/changeset/base/212470 Log: MFC r211419: Since top displays the uptime including seconds, there is no need to add 30 onto it, which may have been used for rounding purposes in other utilities. PR: bin/147934 Submitted by: Janne Snabb Approved by: rrs (mentor) Modified: stable/8/contrib/top/display.c Directory Properties: stable/8/contrib/top/ (props changed) stable/8/contrib/top/install-sh (props changed) Modified: stable/8/contrib/top/display.c ============================================================================== --- stable/8/contrib/top/display.c Sat Sep 11 14:21:02 2010 (r212469) +++ stable/8/contrib/top/display.c Sat Sep 11 14:26:18 2010 (r212470) @@ -1273,7 +1273,6 @@ time_t *tod; if (bt->tv_sec != -1) { uptime = *tod - bt->tv_sec; - uptime += 30; days = uptime / 86400; uptime %= 86400; hrs = uptime / 3600; From owner-svn-src-stable@FreeBSD.ORG Sat Sep 11 14:29:31 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8D3E81065672; Sat, 11 Sep 2010 14:29:31 +0000 (UTC) (envelope-from brucec@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 7C86B8FC20; Sat, 11 Sep 2010 14:29:31 +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 o8BETVuX005098; Sat, 11 Sep 2010 14:29:31 GMT (envelope-from brucec@svn.freebsd.org) Received: (from brucec@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o8BETVJb005096; Sat, 11 Sep 2010 14:29:31 GMT (envelope-from brucec@svn.freebsd.org) Message-Id: <201009111429.o8BETVJb005096@svn.freebsd.org> From: Bruce Cran Date: Sat, 11 Sep 2010 14:29:31 +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: r212471 - stable/7/contrib/top X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Sep 2010 14:29:31 -0000 Author: brucec Date: Sat Sep 11 14:29:31 2010 New Revision: 212471 URL: http://svn.freebsd.org/changeset/base/212471 Log: MFC r211419: Since top displays the uptime including seconds, there is no need to add 30 onto it, which may have been used for rounding purposes in other utilities. PR: bin/147934 Submitted by: Janne Snabb Approved by: rrs (mentor) Modified: stable/7/contrib/top/display.c Directory Properties: stable/7/contrib/top/ (props changed) Modified: stable/7/contrib/top/display.c ============================================================================== --- stable/7/contrib/top/display.c Sat Sep 11 14:26:18 2010 (r212470) +++ stable/7/contrib/top/display.c Sat Sep 11 14:29:31 2010 (r212471) @@ -1273,7 +1273,6 @@ time_t *tod; if (bt->tv_sec != -1) { uptime = *tod - bt->tv_sec; - uptime += 30; days = uptime / 86400; uptime %= 86400; hrs = uptime / 3600; From owner-svn-src-stable@FreeBSD.ORG Sat Sep 11 14:34:16 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EA71310656A3; Sat, 11 Sep 2010 14:34:16 +0000 (UTC) (envelope-from brucec@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D8D9C8FC13; Sat, 11 Sep 2010 14:34:16 +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 o8BEYG3W005527; Sat, 11 Sep 2010 14:34:16 GMT (envelope-from brucec@svn.freebsd.org) Received: (from brucec@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o8BEYGn7005524; Sat, 11 Sep 2010 14:34:16 GMT (envelope-from brucec@svn.freebsd.org) Message-Id: <201009111434.o8BEYGn7005524@svn.freebsd.org> From: Bruce Cran Date: Sat, 11 Sep 2010 14:34:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212472 - stable/8/usr.sbin/powerd X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Sep 2010 14:34:17 -0000 Author: brucec Date: Sat Sep 11 14:34:16 2010 New Revision: 212472 URL: http://svn.freebsd.org/changeset/base/212472 Log: MFC r211415: Add -m and -M options to control the minimum and maximum frequency. PR: bin/145063 Submitted by: Boris Kochergin Approved by: rrs (mentor) Modified: stable/8/usr.sbin/powerd/powerd.8 stable/8/usr.sbin/powerd/powerd.c Directory Properties: stable/8/usr.sbin/powerd/ (props changed) Modified: stable/8/usr.sbin/powerd/powerd.8 ============================================================================== --- stable/8/usr.sbin/powerd/powerd.8 Sat Sep 11 14:29:31 2010 (r212471) +++ stable/8/usr.sbin/powerd/powerd.8 Sat Sep 11 14:34:16 2010 (r212472) @@ -35,6 +35,8 @@ .Op Fl a Ar mode .Op Fl b Ar mode .Op Fl i Ar percent +.Op Fl m Ar freq +.Op Fl M Ar freq .Op Fl n Ar mode .Op Fl p Ar ival .Op Fl P Ar pidfile @@ -79,6 +81,10 @@ to use while on battery power. Specifies the CPU load percent level when adaptive mode should begin to degrade performance to save power. The default is 50% or lower. +.It Fl m Ar freq +Specifies the minimum frequency to throttle down to. +.It Fl M Ar freq +Specifies the maximum frequency to throttle up to. .It Fl n Ar mode Selects the .Ar mode Modified: stable/8/usr.sbin/powerd/powerd.c ============================================================================== --- stable/8/usr.sbin/powerd/powerd.c Sat Sep 11 14:29:31 2010 (r212471) +++ stable/8/usr.sbin/powerd/powerd.c Sat Sep 11 14:34:16 2010 (r212472) @@ -80,7 +80,8 @@ const char *modes[] = { #define DEVCTL_MAXBUF 1024 static int read_usage_times(int *load); -static int read_freqs(int *numfreqs, int **freqs, int **power); +static int read_freqs(int *numfreqs, int **freqs, int **power, + int minfreq, int maxfreq); static int set_freq(int freq); static void acline_init(void); static void acline_read(void); @@ -170,10 +171,10 @@ read_usage_times(int *load) } static int -read_freqs(int *numfreqs, int **freqs, int **power) +read_freqs(int *numfreqs, int **freqs, int **power, int minfreq, int maxfreq) { char *freqstr, *p, *q; - int i; + int i, j; size_t len = 0; if (sysctl(levels_mib, 4, NULL, &len, NULL, 0)) @@ -197,19 +198,30 @@ read_freqs(int *numfreqs, int **freqs, i free(*freqs); return (-1); } - for (i = 0, p = freqstr; i < *numfreqs; i++) { + for (i = 0, j = 0, p = freqstr; i < *numfreqs; i++) { q = strchr(p, ' '); if (q != NULL) *q = '\0'; - if (sscanf(p, "%d/%d", &(*freqs)[i], &(*power)[i]) != 2) { + if (sscanf(p, "%d/%d", &(*freqs)[j], &(*power)[i]) != 2) { free(freqstr); free(*freqs); free(*power); return (-1); } + if (((*freqs)[j] >= minfreq || minfreq == -1) && + ((*freqs)[j] <= maxfreq || maxfreq == -1)) + j++; p = q + 1; } + *numfreqs = j; + if ((*freqs = realloc(*freqs, *numfreqs * sizeof(int))) == NULL) { + free(freqstr); + free(*freqs); + free(*power); + return (-1); + } + free(freqstr); return (0); } @@ -418,7 +430,7 @@ usage(void) { fprintf(stderr, -"usage: powerd [-v] [-a mode] [-b mode] [-i %%] [-n mode] [-p ival] [-r %%] [-P pidfile]\n"); +"usage: powerd [-v] [-a mode] [-b mode] [-i %%] [-m freq] [-M freq] [-n mode] [-p ival] [-r %%] [-P pidfile]\n"); exit(1); } @@ -431,7 +443,8 @@ main(int argc, char * argv[]) struct pidfh *pfh = NULL; const char *pidfile = NULL; int freq, curfreq, initfreq, *freqs, i, j, *mwatts, numfreqs, load; - int ch, mode, mode_ac, mode_battery, mode_none; + int ch, mode, mode_ac, mode_battery, mode_none, idle; + int minfreq = -1, maxfreq = -1; uint64_t mjoules_used; size_t len; @@ -448,7 +461,7 @@ main(int argc, char * argv[]) if (geteuid() != 0) errx(1, "must be root to run"); - while ((ch = getopt(argc, argv, "a:b:i:n:p:P:r:v")) != -1) + while ((ch = getopt(argc, argv, "a:b:i:m:M:n:p:P:r:v")) != -1) switch (ch) { case 'a': parse_mode(optarg, &mode_ac, ch); @@ -464,6 +477,22 @@ main(int argc, char * argv[]) usage(); } break; + case 'm': + minfreq = atoi(optarg); + if (minfreq < 0) { + warnx("%d is not a valid CPU frequency", + minfreq); + usage(); + } + break; + case 'M': + maxfreq = atoi(optarg); + if (maxfreq < 0) { + warnx("%d is not a valid CPU frequency", + maxfreq); + usage(); + } + break; case 'n': parse_mode(optarg, &mode_none, ch); break; @@ -511,8 +540,10 @@ main(int argc, char * argv[]) /* Check if we can read the load and supported freqs. */ if (read_usage_times(NULL)) err(1, "read_usage_times"); - if (read_freqs(&numfreqs, &freqs, &mwatts)) + if (read_freqs(&numfreqs, &freqs, &mwatts, minfreq, maxfreq)) err(1, "error reading supported CPU frequencies"); + if (numfreqs == 0) + errx(1, "no CPU frequencies in user-specified range"); /* Run in the background unless in verbose mode. */ if (!vflag) { @@ -547,6 +578,50 @@ main(int argc, char * argv[]) freq = initfreq = get_freq(); if (freq < 1) freq = 1; + + /* + * If we are in adaptive mode and the current frequency is outside the + * user-defined range, adjust it to be within the user-defined range. + */ + acline_read(); + if (acline_status > SRC_UNKNOWN) + errx(1, "invalid AC line status %d", acline_status); + if ((acline_status == SRC_AC && + (mode_ac == MODE_ADAPTIVE || mode_ac == MODE_HIADAPTIVE)) || + (acline_status == SRC_BATTERY && + (mode_battery == MODE_ADAPTIVE || mode_battery == MODE_HIADAPTIVE)) || + (acline_status == SRC_UNKNOWN && + (mode_none == MODE_ADAPTIVE || mode_none == MODE_HIADAPTIVE))) { + /* Read the current frequency. */ + len = sizeof(curfreq); + if (sysctl(freq_mib, 4, &curfreq, &len, NULL, 0) != 0) { + if (vflag) + warn("error reading current CPU frequency"); + } + if (curfreq < freqs[numfreqs - 1]) { + if (vflag) { + printf("CPU frequency is below user-defined " + "minimum; changing frequency to %d " + "MHz\n", freqs[numfreqs - 1]); + } + if (set_freq(freqs[numfreqs - 1]) != 0) { + warn("error setting CPU freq %d", + freqs[numfreqs - 1]); + } + } else if (curfreq > freqs[0]) { + if (vflag) { + printf("CPU frequency is above user-defined " + "maximum; changing frequency to %d " + "MHz\n", freqs[0]); + } + if (set_freq(freqs[0]) != 0) { + warn("error setting CPU freq %d", + freqs[0]); + } + } + } + + idle = 0; /* Main loop. */ for (;;) { FD_ZERO(&fdset); From owner-svn-src-stable@FreeBSD.ORG Sat Sep 11 14:39:53 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 72EED106564A; Sat, 11 Sep 2010 14:39:53 +0000 (UTC) (envelope-from brucec@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 610E18FC12; Sat, 11 Sep 2010 14:39:53 +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 o8BEdrCY005931; Sat, 11 Sep 2010 14:39:53 GMT (envelope-from brucec@svn.freebsd.org) Received: (from brucec@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o8BEdrKd005928; Sat, 11 Sep 2010 14:39:53 GMT (envelope-from brucec@svn.freebsd.org) Message-Id: <201009111439.o8BEdrKd005928@svn.freebsd.org> From: Bruce Cran Date: Sat, 11 Sep 2010 14:39:53 +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: r212473 - stable/7/usr.sbin/powerd X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Sep 2010 14:39:53 -0000 Author: brucec Date: Sat Sep 11 14:39:53 2010 New Revision: 212473 URL: http://svn.freebsd.org/changeset/base/212473 Log: MFC r211415: Add -m and -M options to control the minimum and maximum frequency. PR: bin/145063 Submitted by: Boris Kochergin Approved by: rrs (mentor) Modified: stable/7/usr.sbin/powerd/powerd.8 stable/7/usr.sbin/powerd/powerd.c Directory Properties: stable/7/usr.sbin/powerd/ (props changed) Modified: stable/7/usr.sbin/powerd/powerd.8 ============================================================================== --- stable/7/usr.sbin/powerd/powerd.8 Sat Sep 11 14:34:16 2010 (r212472) +++ stable/7/usr.sbin/powerd/powerd.8 Sat Sep 11 14:39:53 2010 (r212473) @@ -35,6 +35,8 @@ .Op Fl a Ar mode .Op Fl b Ar mode .Op Fl i Ar percent +.Op Fl m Ar freq +.Op Fl M Ar freq .Op Fl n Ar mode .Op Fl p Ar ival .Op Fl P Ar pidfile @@ -78,6 +80,10 @@ to use while on battery power. Specifies the CPU load percent level when adaptive mode should begin to degrade performance to save power. The default is 50% or lower. +.It Fl m Ar freq +Specifies the minimum frequency to throttle down to. +.It Fl M Ar freq +Specifies the maximum frequency to throttle up to. .It Fl n Ar mode Selects the .Ar mode Modified: stable/7/usr.sbin/powerd/powerd.c ============================================================================== --- stable/7/usr.sbin/powerd/powerd.c Sat Sep 11 14:34:16 2010 (r212472) +++ stable/7/usr.sbin/powerd/powerd.c Sat Sep 11 14:39:53 2010 (r212473) @@ -79,7 +79,8 @@ const char *modes[] = { #define DEVCTL_MAXBUF 1024 static int read_usage_times(int *load); -static int read_freqs(int *numfreqs, int **freqs, int **power); +static int read_freqs(int *numfreqs, int **freqs, int **power, + int minfreq, int maxfreq); static int set_freq(int freq); static void acline_init(void); static void acline_read(void); @@ -168,10 +169,10 @@ read_usage_times(int *load) } static int -read_freqs(int *numfreqs, int **freqs, int **power) +read_freqs(int *numfreqs, int **freqs, int **power, int minfreq, int maxfreq) { char *freqstr, *p, *q; - int i; + int i, j; size_t len = 0; if (sysctl(levels_mib, 4, NULL, &len, NULL, 0)) @@ -195,19 +196,30 @@ read_freqs(int *numfreqs, int **freqs, i free(*freqs); return (-1); } - for (i = 0, p = freqstr; i < *numfreqs; i++) { + for (i = 0, j = 0, p = freqstr; i < *numfreqs; i++) { q = strchr(p, ' '); if (q != NULL) *q = '\0'; - if (sscanf(p, "%d/%d", &(*freqs)[i], &(*power)[i]) != 2) { + if (sscanf(p, "%d/%d", &(*freqs)[j], &(*power)[i]) != 2) { free(freqstr); free(*freqs); free(*power); return (-1); } + if (((*freqs)[j] >= minfreq || minfreq == -1) && + ((*freqs)[j] <= maxfreq || maxfreq == -1)) + j++; p = q + 1; } + *numfreqs = j; + if ((*freqs = realloc(*freqs, *numfreqs * sizeof(int))) == NULL) { + free(freqstr); + free(*freqs); + free(*power); + return (-1); + } + free(freqstr); return (0); } @@ -410,7 +422,7 @@ usage(void) { fprintf(stderr, -"usage: powerd [-v] [-a mode] [-b mode] [-i %%] [-n mode] [-p ival] [-r %%] [-P pidfile]\n"); +"usage: powerd [-v] [-a mode] [-b mode] [-i %%] [-m freq] [-M freq] [-n mode] [-p ival] [-r %%] [-P pidfile]\n"); exit(1); } @@ -424,6 +436,7 @@ main(int argc, char * argv[]) const char *pidfile = NULL; int freq, curfreq, initfreq, *freqs, i, j, *mwatts, numfreqs, load; int ch, mode, mode_ac, mode_battery, mode_none; + int minfreq = -1, maxfreq = -1; uint64_t mjoules_used; size_t len; @@ -440,7 +453,7 @@ main(int argc, char * argv[]) if (geteuid() != 0) errx(1, "must be root to run"); - while ((ch = getopt(argc, argv, "a:b:i:n:p:P:r:v")) != -1) + while ((ch = getopt(argc, argv, "a:b:i:m:M:n:p:P:r:v")) != -1) switch (ch) { case 'a': parse_mode(optarg, &mode_ac, ch); @@ -456,6 +469,22 @@ main(int argc, char * argv[]) usage(); } break; + case 'm': + minfreq = atoi(optarg); + if (minfreq < 0) { + warnx("%d is not a valid CPU frequency", + minfreq); + usage(); + } + break; + case 'M': + maxfreq = atoi(optarg); + if (maxfreq < 0) { + warnx("%d is not a valid CPU frequency", + maxfreq); + usage(); + } + break; case 'n': parse_mode(optarg, &mode_none, ch); break; @@ -503,8 +532,10 @@ main(int argc, char * argv[]) /* Check if we can read the load and supported freqs. */ if (read_usage_times(NULL)) err(1, "read_usage_times"); - if (read_freqs(&numfreqs, &freqs, &mwatts)) + if (read_freqs(&numfreqs, &freqs, &mwatts, minfreq, maxfreq)) err(1, "error reading supported CPU frequencies"); + if (numfreqs == 0) + errx(1, "no CPU frequencies in user-specified range"); /* Run in the background unless in verbose mode. */ if (!vflag) { @@ -539,6 +570,49 @@ main(int argc, char * argv[]) freq = initfreq = get_freq(); if (freq < 1) freq = 1; + + /* + * If we are in adaptive mode and the current frequency is outside the + * user-defined range, adjust it to be within the user-defined range. + */ + acline_read(); + if (acline_status > SRC_UNKNOWN) + errx(1, "invalid AC line status %d", acline_status); + if ((acline_status == SRC_AC && + (mode_ac == MODE_ADAPTIVE || mode_ac == MODE_HIADAPTIVE)) || + (acline_status == SRC_BATTERY && + (mode_battery == MODE_ADAPTIVE || mode_battery == MODE_HIADAPTIVE)) || + (acline_status == SRC_UNKNOWN && + (mode_none == MODE_ADAPTIVE || mode_none == MODE_HIADAPTIVE))) { + /* Read the current frequency. */ + len = sizeof(curfreq); + if (sysctl(freq_mib, 4, &curfreq, &len, NULL, 0) != 0) { + if (vflag) + warn("error reading current CPU frequency"); + } + if (curfreq < freqs[numfreqs - 1]) { + if (vflag) { + printf("CPU frequency is below user-defined " + "minimum; changing frequency to %d " + "MHz\n", freqs[numfreqs - 1]); + } + if (set_freq(freqs[numfreqs - 1]) != 0) { + warn("error setting CPU freq %d", + freqs[numfreqs - 1]); + } + } else if (curfreq > freqs[0]) { + if (vflag) { + printf("CPU frequency is above user-defined " + "maximum; changing frequency to %d " + "MHz\n", freqs[0]); + } + if (set_freq(freqs[0]) != 0) { + warn("error setting CPU freq %d", + freqs[0]); + } + } + } + /* Main loop. */ for (;;) { FD_ZERO(&fdset); From owner-svn-src-stable@FreeBSD.ORG Sat Sep 11 14:46:20 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BDEAC1065670; Sat, 11 Sep 2010 14:46:20 +0000 (UTC) (envelope-from brucec@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id ACBF58FC1A; Sat, 11 Sep 2010 14:46:20 +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 o8BEkJEQ006555; Sat, 11 Sep 2010 14:46:19 GMT (envelope-from brucec@svn.freebsd.org) Received: (from brucec@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o8BEkJUR006553; Sat, 11 Sep 2010 14:46:19 GMT (envelope-from brucec@svn.freebsd.org) Message-Id: <201009111446.o8BEkJUR006553@svn.freebsd.org> From: Bruce Cran Date: Sat, 11 Sep 2010 14:46:19 +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: r212474 - stable/7/sys/boot/forth X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Sep 2010 14:46:20 -0000 Author: brucec Date: Sat Sep 11 14:46:19 2010 New Revision: 212474 URL: http://svn.freebsd.org/changeset/base/212474 Log: MFC r182194: Add geom_journal PR: conf/126829 Approved by: rrs (mentor) Modified: stable/7/sys/boot/forth/loader.conf 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/boot/forth/loader.conf ============================================================================== --- stable/7/sys/boot/forth/loader.conf Sat Sep 11 14:39:53 2010 (r212473) +++ stable/7/sys/boot/forth/loader.conf Sat Sep 11 14:46:19 2010 (r212474) @@ -149,6 +149,7 @@ geom_concat_load="NO" # Concatenated di geom_eli_load="NO" # Disk encryption driver (see geli(8)) geom_gate_load="NO" # Userland disk driver (see geom_gate(4), # ggatec(8), ggated(8), ggatel(8)) +geom_journal_load="NO" # Journaled filesystem driver (see gjournal(8)) geom_label_load="NO" # File system labels (see glabel(8)) geom_md_load="NO" # Memory disk driver (vnode/swap/malloc) (see # md(4), mdconfig(8)) From owner-svn-src-stable@FreeBSD.ORG Sat Sep 11 14:53:37 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AE32A106566C; Sat, 11 Sep 2010 14:53:37 +0000 (UTC) (envelope-from bruce@cran.org.uk) Received: from april.london.02.net (april.london.02.net [87.194.255.143]) by mx1.freebsd.org (Postfix) with ESMTP id 485428FC08; Sat, 11 Sep 2010 14:53:37 +0000 (UTC) Received: from core.draftnet (94.193.93.212) by april.london.02.net (8.5.124.10) id 4C888693001259A8; Sat, 11 Sep 2010 15:42:16 +0100 From: Bruce Cran To: Bruce Cran Date: Sat, 11 Sep 2010 15:42:15 +0100 User-Agent: KMail/1.13.5 (FreeBSD/9.0-CURRENT; KDE/4.5.1; amd64; ; ) References: <201009111434.o8BEYGn7005524@svn.freebsd.org> In-Reply-To: <201009111434.o8BEYGn7005524@svn.freebsd.org> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <201009111542.15446.bruce@cran.org.uk> Cc: svn-src-stable@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, svn-src-stable-8@freebsd.org Subject: Re: svn commit: r212472 - stable/8/usr.sbin/powerd X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Sep 2010 14:53:37 -0000 On Saturday 11 September 2010 15:34:16 Bruce Cran wrote: > Author: brucec > Date: Sat Sep 11 14:34:16 2010 > New Revision: 212472 > URL: http://svn.freebsd.org/changeset/base/212472 > > Log: > MFC r211415: > > Add -m and -M options to control the minimum and maximum frequency. > > PR: bin/145063 > Submitted by: Boris Kochergin > Approved by: rrs (mentor) > > Modified: > stable/8/usr.sbin/powerd/powerd.8 > stable/8/usr.sbin/powerd/powerd.c > Directory Properties: > stable/8/usr.sbin/powerd/ (props changed) > > [...] > + int ch, mode, mode_ac, mode_battery, mode_none, idle; > [...] > + idle = 0; 'idle' shouldn't have been merged here. I'll fix it in a followup checkin. -- Bruce Cran From owner-svn-src-stable@FreeBSD.ORG Sat Sep 11 15:01:10 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4D71D106566B; Sat, 11 Sep 2010 15:01:10 +0000 (UTC) (envelope-from itetcu@FreeBSD.org) Received: from worf.ds9.tecnik93.com (worf.ds9.tecnik93.com [81.196.207.130]) by mx1.freebsd.org (Postfix) with ESMTP id 034218FC08; Sat, 11 Sep 2010 15:01:09 +0000 (UTC) Received: from it.buh.tecnik93.com (it.buh.tecnik93.com [81.196.204.98]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by worf.ds9.tecnik93.com (Postfix) with ESMTPSA id 267F522C52F1; Sat, 11 Sep 2010 17:43:43 +0300 (EEST) Date: Sat, 11 Sep 2010 17:43:41 +0300 From: Ion-Mihai Tetcu To: Bruce Cran Message-ID: <20100911174341.660a78dc@it.buh.tecnik93.com> In-Reply-To: <201009111434.o8BEYGn7005524@svn.freebsd.org> References: <201009111434.o8BEYGn7005524@svn.freebsd.org> X-Mailer: Claws Mail 3.7.6 (GTK+ 2.20.1; amd64-portbld-freebsd8.1) Mime-Version: 1.0 Content-Type: multipart/signed; micalg=PGP-SHA1; boundary="Sig_/N4J35v=KX2vRJ1O=o80Ym6m"; protocol="application/pgp-signature" Cc: svn-src-stable@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, svn-src-stable-8@freebsd.org Subject: Re: svn commit: r212472 - stable/8/usr.sbin/powerd X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Sep 2010 15:01:10 -0000 --Sig_/N4J35v=KX2vRJ1O=o80Ym6m Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Sat, 11 Sep 2010 14:34:16 +0000 (UTC) Bruce Cran wrote: > Author: brucec > Date: Sat Sep 11 14:34:16 2010 > New Revision: 212472 > URL: http://svn.freebsd.org/changeset/base/212472 >=20 > Log: > MFC r211415: > =20 > Add -m and -M options to control the minimum and maximum frequency. > =20 > PR: bin/145063 > Submitted by: Boris Kochergin > Approved by: rrs (mentor) Thank you! --=20 IOnut - Un^d^dregistered ;) FreeBSD "user" "Intellectual Property" is nowhere near as valuable as "Intellect" FreeBSD committer -> itetcu@FreeBSD.org, PGP Key ID 057E9F8B493A297B --Sig_/N4J35v=KX2vRJ1O=o80Ym6m Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (FreeBSD) iEYEARECAAYFAkyLlZ4ACgkQJ7GIuiH/oeXHTQCeNodT/PjjW7hjCF6Sd3iGWT6c yhwAoLi60U4LeHyZwBTbQnZCzLbtednc =R0t+ -----END PGP SIGNATURE----- --Sig_/N4J35v=KX2vRJ1O=o80Ym6m-- From owner-svn-src-stable@FreeBSD.ORG Sat Sep 11 18:50:34 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 497E1106566B; Sat, 11 Sep 2010 18:50:34 +0000 (UTC) (envelope-from gavin@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 37E038FC17; Sat, 11 Sep 2010 18:50:34 +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 o8BIoYi0028632; Sat, 11 Sep 2010 18:50:34 GMT (envelope-from gavin@svn.freebsd.org) Received: (from gavin@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o8BIoYem028630; Sat, 11 Sep 2010 18:50:34 GMT (envelope-from gavin@svn.freebsd.org) Message-Id: <201009111850.o8BIoYem028630@svn.freebsd.org> From: Gavin Atkinson Date: Sat, 11 Sep 2010 18:50:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212476 - stable/8/usr.bin/split X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Sep 2010 18:50:34 -0000 Author: gavin Date: Sat Sep 11 18:50:33 2010 New Revision: 212476 URL: http://svn.freebsd.org/changeset/base/212476 Log: Merge r212162 from head: Correct spelling mistake, int -> into Modified: stable/8/usr.bin/split/split.1 Directory Properties: stable/8/usr.bin/split/ (props changed) Modified: stable/8/usr.bin/split/split.1 ============================================================================== --- stable/8/usr.bin/split/split.1 Sat Sep 11 15:07:40 2010 (r212475) +++ stable/8/usr.bin/split/split.1 Sat Sep 11 18:50:33 2010 (r212476) @@ -32,7 +32,7 @@ .\" @(#)split.1 8.3 (Berkeley) 4/16/94 .\" $FreeBSD$ .\" -.Dd January 23, 2009 +.Dd September 2, 2010 .Dt SPLIT 1 .Os .Sh NAME @@ -117,7 +117,7 @@ Create split files .Ar line_count lines in length. .It Fl n Ar chunk_count -Split file int +Split file into .Ar chunk_count smaller files. .It Fl p Ar pattern From owner-svn-src-stable@FreeBSD.ORG Sat Sep 11 21:52:40 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BDEC5106564A; Sat, 11 Sep 2010 21:52:40 +0000 (UTC) (envelope-from brucec@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id AC8D88FC1E; Sat, 11 Sep 2010 21:52:40 +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 o8BLqew2045693; Sat, 11 Sep 2010 21:52:40 GMT (envelope-from brucec@svn.freebsd.org) Received: (from brucec@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o8BLqeYS045691; Sat, 11 Sep 2010 21:52:40 GMT (envelope-from brucec@svn.freebsd.org) Message-Id: <201009112152.o8BLqeYS045691@svn.freebsd.org> From: Bruce Cran Date: Sat, 11 Sep 2010 21:52:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212481 - stable/8/usr.sbin/powerd X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Sep 2010 21:52:40 -0000 Author: brucec Date: Sat Sep 11 21:52:40 2010 New Revision: 212481 URL: http://svn.freebsd.org/changeset/base/212481 Log: Remove unused variable 'idle' which mistakenly got merged in r212472. Approved by: rrs (mentor) Modified: stable/8/usr.sbin/powerd/powerd.c Modified: stable/8/usr.sbin/powerd/powerd.c ============================================================================== --- stable/8/usr.sbin/powerd/powerd.c Sat Sep 11 21:49:28 2010 (r212480) +++ stable/8/usr.sbin/powerd/powerd.c Sat Sep 11 21:52:40 2010 (r212481) @@ -443,7 +443,7 @@ main(int argc, char * argv[]) struct pidfh *pfh = NULL; const char *pidfile = NULL; int freq, curfreq, initfreq, *freqs, i, j, *mwatts, numfreqs, load; - int ch, mode, mode_ac, mode_battery, mode_none, idle; + int ch, mode, mode_ac, mode_battery, mode_none; int minfreq = -1, maxfreq = -1; uint64_t mjoules_used; size_t len; @@ -621,7 +621,6 @@ main(int argc, char * argv[]) } } - idle = 0; /* Main loop. */ for (;;) { FD_ZERO(&fdset); From owner-svn-src-stable@FreeBSD.ORG Sat Sep 11 22:02:36 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 738331065670; Sat, 11 Sep 2010 22:02:36 +0000 (UTC) (envelope-from will@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 605E18FC08; Sat, 11 Sep 2010 22:02:36 +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 o8BM2aOE046743; Sat, 11 Sep 2010 22:02:36 GMT (envelope-from will@svn.freebsd.org) Received: (from will@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o8BM2aJL046730; Sat, 11 Sep 2010 22:02:36 GMT (envelope-from will@svn.freebsd.org) Message-Id: <201009112202.o8BM2aJL046730@svn.freebsd.org> From: Will Andrews Date: Sat, 11 Sep 2010 22:02:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212482 - in stable/8/sys: modules modules/if_carp net netinet netinet6 X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Sep 2010 22:02:36 -0000 Author: will Date: Sat Sep 11 22:02:36 2010 New Revision: 212482 URL: http://svn.freebsd.org/changeset/base/212482 Log: MFC r211157, r211193, r212265, r212266: make it possible to load carp(4) as a kld using function pointer hooks and {pf_,ip,ip6}proto_{un,}register(). Reviewed by: bz Approved by: ken (mentor) Added: stable/8/sys/modules/if_carp/ - copied from r211157, head/sys/modules/if_carp/ Modified: stable/8/sys/modules/Makefile stable/8/sys/net/if.c stable/8/sys/net/if_bridge.c stable/8/sys/net/if_ethersubr.c stable/8/sys/netinet/if_ether.c stable/8/sys/netinet/in.c stable/8/sys/netinet/in_proto.c stable/8/sys/netinet/ip_carp.c stable/8/sys/netinet/ip_carp.h stable/8/sys/netinet/ip_input.c stable/8/sys/netinet6/in6_proto.c stable/8/sys/netinet6/nd6_nbr.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/modules/Makefile ============================================================================== --- stable/8/sys/modules/Makefile Sat Sep 11 21:52:40 2010 (r212481) +++ stable/8/sys/modules/Makefile Sat Sep 11 22:02:36 2010 (r212482) @@ -111,6 +111,7 @@ SUBDIR= ${_3dfx} \ ${_ida} \ ${_ie} \ if_bridge \ + if_carp \ if_disc \ if_edsc \ if_ef \ Modified: stable/8/sys/net/if.c ============================================================================== --- stable/8/sys/net/if.c Sat Sep 11 21:52:40 2010 (r212481) +++ stable/8/sys/net/if.c Sat Sep 11 22:02:36 2010 (r212482) @@ -33,7 +33,6 @@ #include "opt_compat.h" #include "opt_inet6.h" #include "opt_inet.h" -#include "opt_carp.h" #include "opt_ddb.h" #include @@ -81,6 +80,7 @@ /*XXX*/ #include #include +#include #ifdef INET6 #include #include @@ -89,11 +89,6 @@ #ifdef INET #include #endif -#if defined(INET) || defined(INET6) -#ifdef DEV_CARP -#include -#endif -#endif #include @@ -128,6 +123,22 @@ SX_SYSINIT(ifdescr_sx, &ifdescr_sx, "ifn void (*bstp_linkstate_p)(struct ifnet *ifp, int state); void (*ng_ether_link_state_p)(struct ifnet *ifp, int state); void (*lagg_linkstate_p)(struct ifnet *ifp, int state); +/* These are external hooks for CARP. */ +void (*carp_linkstate_p)(struct ifnet *ifp); +#if defined(INET) || defined(INET6) +struct ifnet *(*carp_forus_p)(struct ifnet *ifp, u_char *dhost); +int (*carp_output_p)(struct ifnet *ifp, struct mbuf *m, + struct sockaddr *sa, struct rtentry *rt); +#endif +#ifdef INET +int (*carp_iamatch_p)(struct ifnet *, struct in_ifaddr *, struct in_addr *, + u_int8_t **); +#endif +#ifdef INET6 +struct ifaddr *(*carp_iamatch6_p)(struct ifnet *ifp, struct in6_addr *taddr6); +caddr_t (*carp_macmatch6_p)(struct ifnet *ifp, struct mbuf *m, + const struct in6_addr *taddr); +#endif struct mbuf *(*tbr_dequeue_ptr)(struct ifaltq *, int) = NULL; @@ -1851,12 +1862,8 @@ if_unroute(struct ifnet *ifp, int flag, pfctlinput(PRC_IFDOWN, ifa->ifa_addr); ifp->if_qflush(ifp); -#if defined(INET) || defined(INET6) -#ifdef DEV_CARP if (ifp->if_carp) - carp_carpdev_state(ifp->if_carp); -#endif -#endif + (*carp_linkstate_p)(ifp); rt_ifmsg(ifp); } @@ -1877,12 +1884,8 @@ if_route(struct ifnet *ifp, int flag, in TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) if (fam == PF_UNSPEC || (fam == ifa->ifa_addr->sa_family)) pfctlinput(PRC_IFUP, ifa->ifa_addr); -#if defined(INET) || defined(INET6) -#ifdef DEV_CARP if (ifp->if_carp) - carp_carpdev_state(ifp->if_carp); -#endif -#endif + (*carp_linkstate_p)(ifp); rt_ifmsg(ifp); #ifdef INET6 in6_if_up(ifp); @@ -1925,12 +1928,8 @@ do_link_state_change(void *arg, int pend if ((ifp->if_type == IFT_ETHER || ifp->if_type == IFT_L2VLAN) && IFP2AC(ifp)->ac_netgraph != NULL) (*ng_ether_link_state_p)(ifp, link_state); -#if defined(INET) || defined(INET6) -#ifdef DEV_CARP if (ifp->if_carp) - carp_carpdev_state(ifp->if_carp); -#endif -#endif + (*carp_linkstate_p)(ifp); if (ifp->if_bridge) { KASSERT(bstp_linkstate_p != NULL,("if_bridge bstp not loaded!")); (*bstp_linkstate_p)(ifp, link_state); Modified: stable/8/sys/net/if_bridge.c ============================================================================== --- stable/8/sys/net/if_bridge.c Sat Sep 11 21:52:40 2010 (r212481) +++ stable/8/sys/net/if_bridge.c Sat Sep 11 22:02:36 2010 (r212482) @@ -79,7 +79,6 @@ __FBSDID("$FreeBSD$"); #include "opt_inet.h" #include "opt_inet6.h" -#include "opt_carp.h" #include #include @@ -121,10 +120,8 @@ __FBSDID("$FreeBSD$"); #include #endif #if defined(INET) || defined(INET6) -#ifdef DEV_CARP #include #endif -#endif #include #include /* for struct arpcom */ #include @@ -2252,13 +2249,13 @@ bridge_input(struct ifnet *ifp, struct m return (m); } -#if (defined(INET) || defined(INET6)) && defined(DEV_CARP) +#if (defined(INET) || defined(INET6)) # define OR_CARP_CHECK_WE_ARE_DST(iface) \ || ((iface)->if_carp \ - && carp_forus((iface)->if_carp, eh->ether_dhost)) + && (*carp_forus_p)((iface), eh->ether_dhost)) # define OR_CARP_CHECK_WE_ARE_SRC(iface) \ || ((iface)->if_carp \ - && carp_forus((iface)->if_carp, eh->ether_shost)) + && (*carp_forus_p)((iface), eh->ether_shost)) #else # define OR_CARP_CHECK_WE_ARE_DST(iface) # define OR_CARP_CHECK_WE_ARE_SRC(iface) Modified: stable/8/sys/net/if_ethersubr.c ============================================================================== --- stable/8/sys/net/if_ethersubr.c Sat Sep 11 21:52:40 2010 (r212481) +++ stable/8/sys/net/if_ethersubr.c Sat Sep 11 22:02:36 2010 (r212482) @@ -35,7 +35,6 @@ #include "opt_inet6.h" #include "opt_ipx.h" #include "opt_netgraph.h" -#include "opt_carp.h" #include "opt_mbuf_profiling.h" #include @@ -70,6 +69,7 @@ #include #include #include +#include #include #include #include @@ -78,12 +78,6 @@ #include #endif -#if defined(INET) || defined(INET6) -#ifdef DEV_CARP -#include -#endif -#endif - #ifdef IPX #include #include @@ -402,12 +396,10 @@ ether_output(struct ifnet *ifp, struct m } #if defined(INET) || defined(INET6) -#ifdef DEV_CARP if (ifp->if_carp && - (error = carp_output(ifp, m, dst, NULL))) + (error = (*carp_output_p)(ifp, m, dst, NULL))) goto bad; #endif -#endif /* Handle ng_ether(4) processing, if any */ if (IFP2AC(ifp)->ac_netgraph != NULL) { @@ -727,7 +719,6 @@ ether_input(struct ifnet *ifp, struct mb } #if defined(INET) || defined(INET6) -#ifdef DEV_CARP /* * Clear M_PROMISC on frame so that carp(4) will see it when the * mbuf flows up to Layer 3. @@ -738,11 +729,10 @@ ether_input(struct ifnet *ifp, struct mb * TODO: Maintain a hash table of ethernet addresses other than * ether_dhost which may be active on this ifp. */ - if (ifp->if_carp && carp_forus(ifp->if_carp, eh->ether_dhost)) { + if (ifp->if_carp && (*carp_forus_p)(ifp, eh->ether_dhost)) { m->m_flags &= ~M_PROMISC; } else #endif -#endif { /* * If the frame received was not for our MAC address, set the Modified: stable/8/sys/netinet/if_ether.c ============================================================================== --- stable/8/sys/netinet/if_ether.c Sat Sep 11 21:52:40 2010 (r212481) +++ stable/8/sys/netinet/if_ether.c Sat Sep 11 22:02:36 2010 (r212482) @@ -39,7 +39,6 @@ __FBSDID("$FreeBSD$"); #include "opt_inet.h" -#include "opt_carp.h" #include #include @@ -65,14 +64,13 @@ __FBSDID("$FreeBSD$"); #include #include #include +#if defined(INET) || defined(INET6) +#include +#endif #include #include -#ifdef DEV_CARP -#include -#endif - #include #define SIN(s) ((struct sockaddr_in *)s) @@ -494,9 +492,7 @@ in_arpinput(struct mbuf *m) int op, flags; int req_len; int bridged = 0, is_bridge = 0; -#ifdef DEV_CARP int carp_match = 0; -#endif struct sockaddr_in sin; sin.sin_len = sizeof(struct sockaddr_in); sin.sin_family = AF_INET; @@ -539,16 +535,14 @@ in_arpinput(struct mbuf *m) IN_IFADDR_RUNLOCK(); goto match; } -#ifdef DEV_CARP if (ifp->if_carp != NULL && - carp_iamatch(ifp->if_carp, ia, &isaddr, &enaddr) && + (*carp_iamatch_p)(ifp, ia, &isaddr, &enaddr) && itaddr.s_addr == ia->ia_addr.sin_addr.s_addr) { carp_match = 1; ifa_ref(&ia->ia_ifa); IN_IFADDR_RUNLOCK(); goto match; } -#endif } LIST_FOREACH(ia, INADDR_HASH(isaddr.s_addr), ia_hash) if (((bridged && ia->ia_ifp->if_bridge != NULL) || @@ -648,11 +642,7 @@ match: IF_AFDATA_UNLOCK(ifp); if (la != NULL) { /* the following is not an error when doing bridging */ - if (!bridged && la->lle_tbl->llt_ifp != ifp -#ifdef DEV_CARP - && (ifp->if_type != IFT_CARP || !carp_match) -#endif - ) { + if (!bridged && la->lle_tbl->llt_ifp != ifp && !carp_match) { if (log_arp_wrong_iface) log(LOG_ERR, "arp: %s is on %s " "but got reply from %*D on %s\n", Modified: stable/8/sys/netinet/in.c ============================================================================== --- stable/8/sys/netinet/in.c Sat Sep 11 21:52:40 2010 (r212481) +++ stable/8/sys/netinet/in.c Sat Sep 11 22:02:36 2010 (r212482) @@ -33,7 +33,6 @@ #include __FBSDID("$FreeBSD$"); -#include "opt_carp.h" #include "opt_mpath.h" #include @@ -891,13 +890,11 @@ in_ifinit(struct ifnet *ifp, struct in_i ia->ia_net = i & ia->ia_netmask; ia->ia_subnet = i & ia->ia_subnetmask; in_socktrim(&ia->ia_sockmask); -#ifdef DEV_CARP /* * XXX: carp(4) does not have interface route */ if (ifp->if_type == IFT_CARP) return (0); -#endif /* * Add route for the network. */ @@ -1153,12 +1150,12 @@ in_scrubprefix(struct in_ifaddr *target) * the route itself to it. Make sure that routing daemons * get a heads-up. * - * XXX: a special case for carp(4) interface + * XXX: a special case for carp(4) interface - this should + * be more generally specified as an interface that + * doesn't support such action. */ if ((ia->ia_flags & IFA_ROUTE) == 0 -#ifdef DEV_CARP && (ia->ia_ifp->if_type != IFT_CARP) -#endif ) { IN_IFADDR_RUNLOCK(); rtinit(&(target->ia_ifa), (int)RTM_DELETE, Modified: stable/8/sys/netinet/in_proto.c ============================================================================== --- stable/8/sys/netinet/in_proto.c Sat Sep 11 21:52:40 2010 (r212481) +++ stable/8/sys/netinet/in_proto.c Sat Sep 11 22:02:36 2010 (r212482) @@ -37,7 +37,6 @@ __FBSDID("$FreeBSD$"); #include "opt_ipsec.h" #include "opt_inet6.h" #include "opt_pf.h" -#include "opt_carp.h" #include "opt_sctp.h" #include "opt_mpath.h" @@ -94,10 +93,6 @@ static struct pr_usrreqs nousrreqs; #include #endif -#ifdef DEV_CARP -#include -#endif - extern struct domain inetdomain; /* Spacer for loadable protocols. */ @@ -330,18 +325,6 @@ struct protosw inetsw[] = { .pr_usrreqs = &rip_usrreqs }, #endif /* DEV_PFSYNC */ -#ifdef DEV_CARP -{ - .pr_type = SOCK_RAW, - .pr_domain = &inetdomain, - .pr_protocol = IPPROTO_CARP, - .pr_flags = PR_ATOMIC|PR_ADDR, - .pr_input = carp_input, - .pr_output = (pr_output_t*)rip_output, - .pr_ctloutput = rip_ctloutput, - .pr_usrreqs = &rip_usrreqs -}, -#endif /* DEV_CARP */ /* Spacer n-times for loadable protocols. */ IPPROTOSPACER, IPPROTOSPACER, @@ -413,6 +396,3 @@ SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, #ifdef DEV_PFSYNC SYSCTL_NODE(_net_inet, IPPROTO_PFSYNC, pfsync, CTLFLAG_RW, 0, "PFSYNC"); #endif -#ifdef DEV_CARP -SYSCTL_NODE(_net_inet, IPPROTO_CARP, carp, CTLFLAG_RW, 0, "CARP"); -#endif Modified: stable/8/sys/netinet/ip_carp.c ============================================================================== --- stable/8/sys/netinet/ip_carp.c Sat Sep 11 21:52:40 2010 (r212481) +++ stable/8/sys/netinet/ip_carp.c Sat Sep 11 22:02:36 2010 (r212482) @@ -27,7 +27,6 @@ #include __FBSDID("$FreeBSD$"); -#include "opt_carp.h" #include "opt_bpf.h" #include "opt_inet.h" #include "opt_inet6.h" @@ -44,6 +43,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -79,6 +79,7 @@ __FBSDID("$FreeBSD$"); #ifdef INET6 #include #include +#include #include #include #include @@ -136,6 +137,7 @@ struct carp_softc { int carp_suppress_preempt = 0; int carp_opts[CARPCTL_MAXID] = { 0, 1, 0, 1, 0, 0 }; /* XXX for now */ +SYSCTL_NODE(_net_inet, IPPROTO_CARP, carp, CTLFLAG_RW, 0, "CARP"); SYSCTL_INT(_net_inet_carp, CARPCTL_ALLOW, allow, CTLFLAG_RW, &carp_opts[CARPCTL_ALLOW], 0, "Accept incoming CARP packets"); SYSCTL_INT(_net_inet_carp, CARPCTL_PREEMPT, preempt, CTLFLAG_RW, @@ -160,6 +162,10 @@ struct carp_if { struct mtx vhif_mtx; }; +#define CARP_INET 0 +#define CARP_INET6 1 +static int proto_reg[] = {-1, -1}; + /* Get carp_if from softc. Valid after carp_set_addr{,6}. */ #define SC2CIF(sc) ((struct carp_if *)(sc)->sc_carpdev->if_carp) @@ -1146,14 +1152,15 @@ carp_addrcount(struct carp_if *cif, stru } int -carp_iamatch(void *v, struct in_ifaddr *ia, +carp_iamatch(struct ifnet *ifp, struct in_ifaddr *ia, struct in_addr *isaddr, u_int8_t **enaddr) { - struct carp_if *cif = v; + struct carp_if *cif; struct carp_softc *vh; int index, count = 0; struct ifaddr *ifa; + cif = ifp->if_carp; CARP_LOCK(cif); if (carp_opts[CARPCTL_ARPBALANCE]) { @@ -1222,12 +1229,13 @@ carp_iamatch(void *v, struct in_ifaddr * #ifdef INET6 struct ifaddr * -carp_iamatch6(void *v, struct in6_addr *taddr) +carp_iamatch6(struct ifnet *ifp, struct in6_addr *taddr) { - struct carp_if *cif = v; + struct carp_if *cif; struct carp_softc *vh; struct ifaddr *ifa; + cif = ifp->if_carp; CARP_LOCK(cif); TAILQ_FOREACH(vh, &cif->vhif_vrs, sc_list) { IF_ADDR_LOCK(SC2IFP(vh)); @@ -1250,14 +1258,15 @@ carp_iamatch6(void *v, struct in6_addr * return (NULL); } -void * -carp_macmatch6(void *v, struct mbuf *m, const struct in6_addr *taddr) +caddr_t +carp_macmatch6(struct ifnet *ifp, struct mbuf *m, const struct in6_addr *taddr) { struct m_tag *mtag; - struct carp_if *cif = v; + struct carp_if *cif; struct carp_softc *sc; struct ifaddr *ifa; + cif = ifp->if_carp; CARP_LOCK(cif); TAILQ_FOREACH(sc, &cif->vhif_vrs, sc_list) { IF_ADDR_LOCK(SC2IFP(sc)); @@ -1293,15 +1302,16 @@ carp_macmatch6(void *v, struct mbuf *m, #endif struct ifnet * -carp_forus(void *v, void *dhost) +carp_forus(struct ifnet *ifp, u_char *dhost) { - struct carp_if *cif = v; + struct carp_if *cif; struct carp_softc *vh; u_int8_t *ena = dhost; if (ena[0] || ena[1] || ena[2] != 0x5e || ena[3] || ena[4] != 1) return (NULL); + cif = ifp->if_carp; CARP_LOCK(cif); TAILQ_FOREACH(vh, &cif->vhif_vrs, sc_list) if ((SC2IFP(vh)->if_flags & IFF_UP) && @@ -2209,10 +2219,11 @@ carp_set_state(struct carp_softc *sc, in } void -carp_carpdev_state(void *v) +carp_carpdev_state(struct ifnet *ifp) { - struct carp_if *cif = v; + struct carp_if *cif; + cif = ifp->if_carp; CARP_LOCK(cif); carp_carpdev_state_locked(cif); CARP_UNLOCK(cif); @@ -2263,24 +2274,136 @@ carp_sc_state_locked(struct carp_softc * return; } +#ifdef INET +extern struct domain inetdomain; +static struct protosw in_carp_protosw = { + .pr_type = SOCK_RAW, + .pr_domain = &inetdomain, + .pr_protocol = IPPROTO_CARP, + .pr_flags = PR_ATOMIC|PR_ADDR, + .pr_input = carp_input, + .pr_output = (pr_output_t *)rip_output, + .pr_ctloutput = rip_ctloutput, + .pr_usrreqs = &rip_usrreqs +}; +#endif + +#ifdef INET6 +extern struct domain inet6domain; +static struct ip6protosw in6_carp_protosw = { + .pr_type = SOCK_RAW, + .pr_domain = &inet6domain, + .pr_protocol = IPPROTO_CARP, + .pr_flags = PR_ATOMIC|PR_ADDR, + .pr_input = carp6_input, + .pr_output = rip6_output, + .pr_ctloutput = rip6_ctloutput, + .pr_usrreqs = &rip6_usrreqs +}; +#endif + +static void +carp_mod_cleanup(void) +{ + + if (if_detach_event_tag == NULL) + return; + EVENTHANDLER_DEREGISTER(ifnet_departure_event, if_detach_event_tag); + if_clone_detach(&carp_cloner); +#ifdef INET + if (proto_reg[CARP_INET] == 0) { + (void)ipproto_unregister(IPPROTO_CARP); + pf_proto_unregister(PF_INET, IPPROTO_CARP, SOCK_RAW); + proto_reg[CARP_INET] = -1; + } + carp_iamatch_p = NULL; +#endif +#ifdef INET6 + if (proto_reg[CARP_INET6] == 0) { + (void)ip6proto_unregister(IPPROTO_CARP); + pf_proto_unregister(PF_INET6, IPPROTO_CARP, SOCK_RAW); + proto_reg[CARP_INET6] = -1; + } + carp_iamatch6_p = NULL; + carp_macmatch6_p = NULL; +#endif + carp_linkstate_p = NULL; + carp_forus_p = NULL; + carp_output_p = NULL; + mtx_destroy(&carp_mtx); +} + +static int +carp_mod_load(void) +{ + int err; + + if_detach_event_tag = EVENTHANDLER_REGISTER(ifnet_departure_event, + carp_ifdetach, NULL, EVENTHANDLER_PRI_ANY); + if (if_detach_event_tag == NULL) + return (ENOMEM); + mtx_init(&carp_mtx, "carp_mtx", NULL, MTX_DEF); + LIST_INIT(&carpif_list); + if_clone_attach(&carp_cloner); + carp_linkstate_p = carp_carpdev_state; + carp_forus_p = carp_forus; + carp_output_p = carp_output; +#ifdef INET6 + carp_iamatch6_p = carp_iamatch6; + carp_macmatch6_p = carp_macmatch6; + proto_reg[CARP_INET6] = pf_proto_register(PF_INET6, + (struct protosw *)&in6_carp_protosw); + if (proto_reg[CARP_INET6] != 0) { + printf("carp: error %d attaching to PF_INET6\n", + proto_reg[CARP_INET6]); + carp_mod_cleanup(); + return (EINVAL); + } + err = ip6proto_register(IPPROTO_CARP); + if (err) { + printf("carp: error %d registering with INET6\n", err); + carp_mod_cleanup(); + return (EINVAL); + } +#endif +#ifdef INET + carp_iamatch_p = carp_iamatch; + proto_reg[CARP_INET] = pf_proto_register(PF_INET, &in_carp_protosw); + if (proto_reg[CARP_INET] != 0) { + printf("carp: error %d attaching to PF_INET\n", + proto_reg[CARP_INET]); + carp_mod_cleanup(); + return (EINVAL); + } + err = ipproto_register(IPPROTO_CARP); + if (err) { + printf("carp: error %d registering with INET\n", err); + carp_mod_cleanup(); + return (EINVAL); + } +#endif + return 0; +} + static int carp_modevent(module_t mod, int type, void *data) { switch (type) { case MOD_LOAD: - if_detach_event_tag = EVENTHANDLER_REGISTER(ifnet_departure_event, - carp_ifdetach, NULL, EVENTHANDLER_PRI_ANY); - if (if_detach_event_tag == NULL) - return (ENOMEM); - mtx_init(&carp_mtx, "carp_mtx", NULL, MTX_DEF); - LIST_INIT(&carpif_list); - if_clone_attach(&carp_cloner); - break; - + return carp_mod_load(); + /* NOTREACHED */ case MOD_UNLOAD: - EVENTHANDLER_DEREGISTER(ifnet_departure_event, if_detach_event_tag); - if_clone_detach(&carp_cloner); - mtx_destroy(&carp_mtx); + /* + * XXX: For now, disallow module unloading by default due to + * a race condition where a thread may dereference one of the + * function pointer hooks after the module has been + * unloaded, during processing of a packet, causing a panic. + */ +#ifdef CARPMOD_CAN_UNLOAD + carp_mod_cleanup(); +#else + return (EBUSY); +#endif break; default: @@ -2296,4 +2419,4 @@ static moduledata_t carp_mod = { 0 }; -DECLARE_MODULE(carp, carp_mod, SI_SUB_PSEUDO, SI_ORDER_ANY); +DECLARE_MODULE(carp, carp_mod, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY); Modified: stable/8/sys/netinet/ip_carp.h ============================================================================== --- stable/8/sys/netinet/ip_carp.h Sat Sep 11 21:52:40 2010 (r212481) +++ stable/8/sys/netinet/ip_carp.h Sat Sep 11 22:02:36 2010 (r212482) @@ -157,15 +157,35 @@ struct carpreq { } #ifdef _KERNEL -void carp_carpdev_state(void *); +void carp_carpdev_state(struct ifnet *); void carp_input (struct mbuf *, int); int carp6_input (struct mbuf **, int *, int); int carp_output (struct ifnet *, struct mbuf *, struct sockaddr *, struct rtentry *); -int carp_iamatch (void *, struct in_ifaddr *, struct in_addr *, +int carp_iamatch (struct ifnet *, struct in_ifaddr *, struct in_addr *, u_int8_t **); -struct ifaddr *carp_iamatch6(void *, struct in6_addr *); -void *carp_macmatch6(void *, struct mbuf *, const struct in6_addr *); -struct ifnet *carp_forus (void *, void *); +struct ifaddr *carp_iamatch6(struct ifnet *, struct in6_addr *); +caddr_t carp_macmatch6(struct ifnet *, struct mbuf *, const struct in6_addr *); +struct ifnet *carp_forus (struct ifnet *, u_char *); + +/* These are external networking stack hooks for CARP */ +/* net/if.c */ +extern void (*carp_linkstate_p)(struct ifnet *); +/* net/if_bridge.c net/if_ethersubr.c */ +extern struct ifnet *(*carp_forus_p)(struct ifnet *, u_char *); +/* net/if_ethersubr.c */ +extern int (*carp_output_p)(struct ifnet *, struct mbuf *, + struct sockaddr *, struct rtentry *); +#ifdef INET +/* netinet/if_ether.c */ +extern int (*carp_iamatch_p)(struct ifnet *, struct in_ifaddr *, + struct in_addr *, u_int8_t **); +#endif +#ifdef INET6 +/* netinet6/nd6_nbr.c */ +extern struct ifaddr *(*carp_iamatch6_p)(struct ifnet *, struct in6_addr *); +extern caddr_t (*carp_macmatch6_p)(struct ifnet *, struct mbuf *, + const struct in6_addr *); +#endif #endif #endif /* _IP_CARP_H */ Modified: stable/8/sys/netinet/ip_input.c ============================================================================== --- stable/8/sys/netinet/ip_input.c Sat Sep 11 21:52:40 2010 (r212481) +++ stable/8/sys/netinet/ip_input.c Sat Sep 11 22:02:36 2010 (r212482) @@ -37,7 +37,6 @@ __FBSDID("$FreeBSD$"); #include "opt_ipstealth.h" #include "opt_ipsec.h" #include "opt_route.h" -#include "opt_carp.h" #include #include @@ -74,9 +73,7 @@ __FBSDID("$FreeBSD$"); #include #include #include -#ifdef DEV_CARP #include -#endif #ifdef IPSEC #include #endif /* IPSEC */ @@ -606,10 +603,7 @@ passin: */ checkif = V_ip_checkinterface && (V_ipforwarding == 0) && ifp != NULL && ((ifp->if_flags & IFF_LOOPBACK) == 0) && -#ifdef DEV_CARP - !ifp->if_carp && -#endif - (dchg == 0); + ifp->if_carp == NULL && (dchg == 0); /* * Check for exact addresses in the hash bucket. Modified: stable/8/sys/netinet6/in6_proto.c ============================================================================== --- stable/8/sys/netinet6/in6_proto.c Sat Sep 11 21:52:40 2010 (r212481) +++ stable/8/sys/netinet6/in6_proto.c Sat Sep 11 22:02:36 2010 (r212482) @@ -67,7 +67,6 @@ __FBSDID("$FreeBSD$"); #include "opt_inet6.h" #include "opt_ipsec.h" #include "opt_ipstealth.h" -#include "opt_carp.h" #include "opt_sctp.h" #include "opt_mpath.h" @@ -111,10 +110,6 @@ __FBSDID("$FreeBSD$"); #include #include -#ifdef DEV_CARP -#include -#endif - #ifdef SCTP #include #include @@ -331,18 +326,6 @@ struct ip6protosw inet6sw[] = { .pr_ctloutput = rip6_ctloutput, .pr_usrreqs = &rip6_usrreqs }, -#ifdef DEV_CARP -{ - .pr_type = SOCK_RAW, - .pr_domain = &inet6domain, - .pr_protocol = IPPROTO_CARP, - .pr_flags = PR_ATOMIC|PR_ADDR, - .pr_input = carp6_input, - .pr_output = rip6_output, - .pr_ctloutput = rip6_ctloutput, - .pr_usrreqs = &rip6_usrreqs -}, -#endif /* DEV_CARP */ /* Spacer n-times for loadable protocols. */ IP6PROTOSPACER, IP6PROTOSPACER, Modified: stable/8/sys/netinet6/nd6_nbr.c ============================================================================== --- stable/8/sys/netinet6/nd6_nbr.c Sat Sep 11 21:52:40 2010 (r212481) +++ stable/8/sys/netinet6/nd6_nbr.c Sat Sep 11 22:02:36 2010 (r212482) @@ -35,7 +35,6 @@ __FBSDID("$FreeBSD$"); #include "opt_inet.h" #include "opt_inet6.h" #include "opt_ipsec.h" -#include "opt_carp.h" #include "opt_mpath.h" #include @@ -73,10 +72,7 @@ __FBSDID("$FreeBSD$"); #include #include #include - -#ifdef DEV_CARP #include -#endif #define SDL(s) ((struct sockaddr_dl *)s) @@ -222,14 +218,10 @@ nd6_ns_input(struct mbuf *m, int off, in * (3) "tentative" address on which DAD is being performed. */ /* (1) and (3) check. */ -#ifdef DEV_CARP if (ifp->if_carp) - ifa = carp_iamatch6(ifp->if_carp, &taddr6); + ifa = (*carp_iamatch6_p)(ifp, &taddr6); if (ifa == NULL) ifa = (struct ifaddr *)in6ifa_ifpwithaddr(ifp, &taddr6); -#else - ifa = (struct ifaddr *)in6ifa_ifpwithaddr(ifp, &taddr6); -#endif /* (2) check. */ if (ifa == NULL) { @@ -1029,14 +1021,10 @@ nd6_na_output(struct ifnet *ifp, const s * my address) use lladdr configured for the interface. */ if (sdl0 == NULL) { -#ifdef DEV_CARP if (ifp->if_carp) - mac = carp_macmatch6(ifp->if_carp, m, taddr6); + mac = (*carp_macmatch6_p)(ifp, m, taddr6); if (mac == NULL) mac = nd6_ifptomac(ifp); -#else - mac = nd6_ifptomac(ifp); -#endif } else if (sdl0->sa_family == AF_LINK) { struct sockaddr_dl *sdl; sdl = (struct sockaddr_dl *)sdl0;