From owner-svn-src-head@freebsd.org Thu Aug 23 05:06:21 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7265B1080205; Thu, 23 Aug 2018 05:06:21 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 066A17FB8A; Thu, 23 Aug 2018 05:06:18 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D454D1D72C; Thu, 23 Aug 2018 05:06:17 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w7N56HoA062945; Thu, 23 Aug 2018 05:06:17 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w7N56HjE062942; Thu, 23 Aug 2018 05:06:17 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201808230506.w7N56HjE062942@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Thu, 23 Aug 2018 05:06:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r338236 - in head: sbin/devmatch sys/kern sys/sys X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: in head: sbin/devmatch sys/kern sys/sys X-SVN-Commit-Revision: 338236 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Aug 2018 05:06:21 -0000 Author: imp Date: Thu Aug 23 05:06:16 2018 New Revision: 338236 URL: https://svnweb.freebsd.org/changeset/base/338236 Log: Add a new device flag: DF_ATTACHED_ONCE This flag is set once the device has been successfully attached. When set, it inhibits devmatch from trying to match the device. This in turn allows kldunload to work as expected. Prior to the change, the driver would immediately reload because devmatch had no notion that the driver had once been attached, and therefore shouldn't participate in further matching. Differential Revision: https://reviews.freebsd.org/D16735 Modified: head/sbin/devmatch/devmatch.c head/sys/kern/subr_bus.c head/sys/sys/bus.h Modified: head/sbin/devmatch/devmatch.c ============================================================================== --- head/sbin/devmatch/devmatch.c Thu Aug 23 05:06:11 2018 (r338235) +++ head/sbin/devmatch/devmatch.c Thu Aug 23 05:06:16 2018 (r338236) @@ -422,6 +422,8 @@ find_unmatched(struct devinfo_dev *dev, void *arg) break; if (!(dev->dd_flags & DF_ENABLED)) break; + if (dev->dd_flags & DF_ATTACHED_ONCE) + break; parent = devinfo_handle_to_device(dev->dd_parent); bus = strdup(parent->dd_name); p = bus + strlen(bus) - 1; Modified: head/sys/kern/subr_bus.c ============================================================================== --- head/sys/kern/subr_bus.c Thu Aug 23 05:06:11 2018 (r338235) +++ head/sys/kern/subr_bus.c Thu Aug 23 05:06:16 2018 (r338236) @@ -2950,6 +2950,7 @@ device_attach(device_t dev) dev->state = DS_NOTPRESENT; return (error); } + dev->flags |= DF_ATTACHED_ONCE; attachtime = get_cyclecount() - attachtime; /* * 4 bits per device is a reasonable value for desktop and server Modified: head/sys/sys/bus.h ============================================================================== --- head/sys/sys/bus.h Thu Aug 23 05:06:11 2018 (r338235) +++ head/sys/sys/bus.h Thu Aug 23 05:06:16 2018 (r338236) @@ -93,6 +93,7 @@ struct u_device { #define DF_REBID 0x80 /* Can rebid after attach */ #define DF_SUSPENDED 0x100 /* Device is suspended. */ #define DF_QUIET_CHILDREN 0x200 /* Default to quiet for all my children */ +#define DF_ATTACHED_ONCE 0x400 /* Has been attached at least once */ #define DF_NEEDNOMATCH 0x800 /* Has a pending NOMATCH event */ /**