From nobody Sun Dec 04 23:33:01 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NQNJt0b8rz4jtY9; Sun, 4 Dec 2022 23:33:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NQNJt08hYz4Hv8; Sun, 4 Dec 2022 23:33:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670196782; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jUm642yC91XOJzCNP7uLsS7a+N/952AJobVqw/CVr+8=; b=Mp0StY2nxt6WXvCsYt+u4XuGEiSaDBE/xbRKiStLA9QKKWoR/Sqs4zTzh2BJzZt2hV1BHn wBqaKmnQ4NSk4CfJH0FvCIm9jJDKwpi6m0Wceb8xScXZx9nspS6l1LgVEULgOLgzQ9iVoP j6lhHRJG1hk/HPi8GdDjfj+MaPdKv4UVAk3DKch/LXP71Y+LZ9Au6UZqLjbTN0yuMUFirz DMetPPGSoTP6o8XgvMD1gn6gxyt1BAVffaXfnq78JOuRR8tuXrzGrUzJp2sBwKNNiewal6 0PswT2eqrgSK7r5xehhainiR+aiqpyE56kB2jzjhTT3R5nzDvx5QJW6fklalOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670196782; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jUm642yC91XOJzCNP7uLsS7a+N/952AJobVqw/CVr+8=; b=xs2BRJmEHs1fn4tCG0qeIJRKiaB65JQSKgBmJsuGsxc/U4ed3L8b+kqm1kg9Dvu9RYe549 vgiNNTEDFnPL9qC4wigqQJsxSdz2XdJjt4hiJRGI9WxUe5Oe7/TD7iE6wu0/W7GooCsdcL c4ppZz5LvIkvVAY0pahZgxebzw8fSJ5GQyUeop6mchojyWAEdurj+jflIvomzfWIcI1xik tLpPkz3o/eV905XhkdsVIroMPenbMh0GCCoj9fN0o0sqxyesv7Ird3tZAfa3NnAPLycAjy kunlb/yr+lsInin8Zds7VKCryn3Q5o3CxYiEyroepMiOYvGvroQxaLb0sot2QA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1670196782; a=rsa-sha256; cv=none; b=fxKcz/gCY3CYq3sfr6m9G2HM5yg3KpF1WtAAWGMcLStUNymomwiWc42zsd+j5wDRxlb9Po MNDpEg9puAe6OVozapekcJJ6ZsaeF0BifS7PMMDtGSe3sCOK2gDB5graBS7O/oJAEPBk+Q ISeNZm6o9vCpVwQpTcIKSgKOixTQtH3M2ADoj1Ttvw+SbfCQyTZ4BC51ANpbeSSqt56oGL +XUkSpln8kk5eVaoU2Xjfhj1Z3BhPr4sdNf4CNKf3tCFmIz1ZKbLZ3ZNqCBSAcU9CYZZy7 zl8Z3ZY/n5k+Tp1gWSZH7MQvyx+KHHuAGjlb+HR4PO0y5sOUsUzmcIzSCkxQ3w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NQNJs6KBJzcSf; Sun, 4 Dec 2022 23:33:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2B4NX15V089127; Sun, 4 Dec 2022 23:33:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2B4NX1JM089126; Sun, 4 Dec 2022 23:33:01 GMT (envelope-from git) Date: Sun, 4 Dec 2022 23:33:01 GMT Message-Id: <202212042333.2B4NX1JM089126@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: aa52c6bdd7b1 - main - newbus: Create a knob to disable devices that fail to attach. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: aa52c6bdd7b157b7c5d9612e4feac5c94f376df6 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=aa52c6bdd7b157b7c5d9612e4feac5c94f376df6 commit aa52c6bdd7b157b7c5d9612e4feac5c94f376df6 Author: Warner Losh AuthorDate: 2022-12-04 23:20:24 +0000 Commit: Warner Losh CommitDate: 2022-12-04 23:20:24 +0000 newbus: Create a knob to disable devices that fail to attach. Normally, when a device fails to attach, we tear down the newbus state for that device so that future driver loads can try again (maybe with a different driver, or maybe with a re-loaded and fixed kld). Sometimes, however, it is desirable to have the device fail permanantly. We do this by calling device_disable() on a failed attached, as well as keeping the device in DS_ATTACHING forever. This prevents retries on that device. This is enabled via hw.bus.disable_failed_devices=1 in either a hint via the loader, or at runtime with a sysctl setting. Setting from 1 -> 0 at runtime will not affect previously disabled devices, however: they remain disabled. They can be re-enabled manually with devctl enable, however. Sponsored by: Netflix Reviewed by: gallatin, hselasky, jhb Differential Revision: https://reviews.freebsd.org/D37517 --- sys/kern/subr_bus.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index 739484ad849a..b9615b033007 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -69,6 +69,10 @@ SYSCTL_NODE(_hw, OID_AUTO, bus, CTLFLAG_RW | CTLFLAG_MPSAFE, NULL, SYSCTL_ROOT_NODE(OID_AUTO, dev, CTLFLAG_RW | CTLFLAG_MPSAFE, NULL, NULL); +static bool disable_failed_devs = false; +SYSCTL_BOOL(_hw_bus, OID_AUTO, disable_failed_devices, CTLFLAG_RWTUN, &disable_failed_devs, + 0, "Do not retry attaching devices that return an error from DEVICE_ATTACH the first time"); + /* * Used to attach drivers to devclasses. */ @@ -2533,12 +2537,29 @@ device_attach(device_t dev) if ((error = DEVICE_ATTACH(dev)) != 0) { printf("device_attach: %s%d attach returned %d\n", dev->driver->name, dev->unit, error); - if (!(dev->flags & DF_FIXEDCLASS)) - devclass_delete_device(dev->devclass, dev); - (void)device_set_driver(dev, NULL); - device_sysctl_fini(dev); - KASSERT(dev->busy == 0, ("attach failed but busy")); - dev->state = DS_NOTPRESENT; + if (disable_failed_devs) { + /* + * When the user has asked to disable failed devices, we + * directly disable the device, but leave it in the + * attaching state. It will not try to probe/attach the + * device further. This leaves the device numbering + * intact for other similar devices in the system. It + * can be removed from this state with devctl. + */ + device_disable(dev); + } else { + /* + * Otherwise, when attach fails, tear down the state + * around that so we can retry when, for example, new + * drivers are loaded. + */ + if (!(dev->flags & DF_FIXEDCLASS)) + devclass_delete_device(dev->devclass, dev); + (void)device_set_driver(dev, NULL); + device_sysctl_fini(dev); + KASSERT(dev->busy == 0, ("attach failed but busy")); + dev->state = DS_NOTPRESENT; + } return (error); } dev->flags |= DF_ATTACHED_ONCE;