Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Dec 2022 14:01:14 -0700
From:      Warner Losh <imp@bsdimp.com>
To:        Cy Schubert <Cy.Schubert@cschubert.com>
Cc:        Warner Losh <imp@freebsd.org>, src-committers <src-committers@freebsd.org>,  "<dev-commits-src-all@freebsd.org>" <dev-commits-src-all@freebsd.org>, dev-commits-src-main@freebsd.org
Subject:   Re: git: aa52c6bdd7b1 - main - newbus: Create a knob to disable devices that fail to attach.
Message-ID:  <CANCZdfpiSYx3UK8zWpjQ1O3iOYFHHKLJuThN8RYAaLXm_YcNnA@mail.gmail.com>
In-Reply-To: <20221205195134.08074206@slippy.cwsent.com>
References:  <202212042333.2B4NX1JM089126@gitrepo.freebsd.org> <20221205195134.08074206@slippy.cwsent.com>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
I think I'll just revert the default change... but in a few hours when I'm
back home.

Warner

On Mon, Dec 5, 2022, 12:51 PM Cy Schubert <Cy.Schubert@cschubert.com> wrote:

> In message <202212042333.2B4NX1JM089126@gitrepo.freebsd.org>, Warner Losh
> write
> s:
> > The branch main has been updated by imp:
> >
> > URL:
> https://cgit.FreeBSD.org/src/commit/?id=aa52c6bdd7b157b7c5d9612e4feac5c9
> > 4f376df6
> >
> > commit aa52c6bdd7b157b7c5d9612e4feac5c94f376df6
> > Author:     Warner Losh <imp@FreeBSD.org>
> > AuthorDate: 2022-12-04 23:20:24 +0000
> > Commit:     Warner Losh <imp@FreeBSD.org>
> > 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_MPSAF
> > E, 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,
> &disab
> > le_failed_devs,
> > +    0, "Do not retry attaching devices that return an error from
> DEVICE_ATTA
> > CH 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, w
> > e
> > +                      * 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;
> >
>
> When switching a KVM console from a FreeBSD machine to another machine
> attached to the KVM the FreeBSD machine will panic. Photo attached.
>
> This probably needs an UPDATING entry explaining that
> hw.bus.disable_failed_devices sysctl/kenv must be zero (0) to avoid the
> panic.
>
> Sorry for taking so long to report this. Had an appointment this morning.
>
>
> Cheers,
> Cy Schubert <Cy.Schubert@cschubert.com>
> FreeBSD UNIX:  <cy@FreeBSD.org>   Web:  https://FreeBSD.org
> NTP:           <cy@nwtime.org>    Web:  https://nwtime.org
>
>                         e^(i*pi)+1=0
>

[-- Attachment #2 --]
<div dir="auto">I think I&#39;ll just revert the default change... but in a few hours when I&#39;m back home.<div dir="auto"><br></div><div dir="auto">Warner </div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Dec 5, 2022, 12:51 PM Cy Schubert &lt;<a href="mailto:Cy.Schubert@cschubert.com">Cy.Schubert@cschubert.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">In message &lt;<a href="mailto:202212042333.2B4NX1JM089126@gitrepo.freebsd.org" target="_blank" rel="noreferrer">202212042333.2B4NX1JM089126@gitrepo.freebsd.org</a>&gt;, Warner Losh <br>
write<br>
s:<br>
&gt; The branch main has been updated by imp:<br>
&gt;<br>
&gt; URL: <a href="https://cgit.FreeBSD.org/src/commit/?id=aa52c6bdd7b157b7c5d9612e4feac5c9" rel="noreferrer noreferrer" target="_blank">https://cgit.FreeBSD.org/src/commit/?id=aa52c6bdd7b157b7c5d9612e4feac5c9</a><br>;
&gt; 4f376df6<br>
&gt;<br>
&gt; commit aa52c6bdd7b157b7c5d9612e4feac5c94f376df6<br>
&gt; Author:     Warner Losh &lt;imp@FreeBSD.org&gt;<br>
&gt; AuthorDate: 2022-12-04 23:20:24 +0000<br>
&gt; Commit:     Warner Losh &lt;imp@FreeBSD.org&gt;<br>
&gt; CommitDate: 2022-12-04 23:20:24 +0000<br>
&gt;<br>
&gt;     newbus: Create a knob to disable devices that fail to attach.<br>
&gt;     <br>
&gt;     Normally, when a device fails to attach, we tear down the newbus state<br>
&gt;     for that device so that future driver loads can try again (maybe with a<br>
&gt;     different driver, or maybe with a re-loaded and fixed kld).<br>
&gt;     <br>
&gt;     Sometimes, however, it is desirable to have the device fail<br>
&gt;     permanantly. We do this by calling device_disable() on a failed<br>
&gt;     attached, as well as keeping the device in DS_ATTACHING forever. This<br>
&gt;     prevents retries on that device. This is enabled via<br>
&gt;     hw.bus.disable_failed_devices=1 in either a hint via the loader, or at<br>
&gt;     runtime with a sysctl setting. Setting from 1 -&gt; 0 at runtime will not<br>
&gt;     affect previously disabled devices, however: they remain disabled.<br>
&gt;     They can be re-enabled manually with devctl enable, however.<br>
&gt;     <br>
&gt;     Sponsored by:           Netflix<br>
&gt;     <br>
&gt;     Reviewed by:    gallatin, hselasky, jhb<br>
&gt;     Differential Revision:  <a href="https://reviews.freebsd.org/D37517" rel="noreferrer noreferrer" target="_blank">https://reviews.freebsd.org/D37517</a><br>;
&gt; ---<br>
&gt;  sys/kern/subr_bus.c | 33 +++++++++++++++++++++++++++------<br>
&gt;  1 file changed, 27 insertions(+), 6 deletions(-)<br>
&gt;<br>
&gt; diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c<br>
&gt; index 739484ad849a..b9615b033007 100644<br>
&gt; --- a/sys/kern/subr_bus.c<br>
&gt; +++ b/sys/kern/subr_bus.c<br>
&gt; @@ -69,6 +69,10 @@ SYSCTL_NODE(_hw, OID_AUTO, bus, CTLFLAG_RW | CTLFLAG_MPSAF<br>
&gt; E, NULL,<br>
&gt;  SYSCTL_ROOT_NODE(OID_AUTO, dev, CTLFLAG_RW | CTLFLAG_MPSAFE, NULL,<br>
&gt;      NULL);<br>
&gt;  <br>
&gt; +static bool disable_failed_devs = false;<br>
&gt; +SYSCTL_BOOL(_hw_bus, OID_AUTO, disable_failed_devices, CTLFLAG_RWTUN, &amp;disab<br>
&gt; le_failed_devs,<br>
&gt; +    0, &quot;Do not retry attaching devices that return an error from DEVICE_ATTA<br>
&gt; CH the first time&quot;);<br>
&gt; +<br>
&gt;  /*<br>
&gt;   * Used to attach drivers to devclasses.<br>
&gt;   */<br>
&gt; @@ -2533,12 +2537,29 @@ device_attach(device_t dev)<br>
&gt;       if ((error = DEVICE_ATTACH(dev)) != 0) {<br>
&gt;               printf(&quot;device_attach: %s%d attach returned %d\n&quot;,<br>
&gt;                   dev-&gt;driver-&gt;name, dev-&gt;unit, error);<br>
&gt; -             if (!(dev-&gt;flags &amp; DF_FIXEDCLASS))<br>
&gt; -                     devclass_delete_device(dev-&gt;devclass, dev);<br>
&gt; -             (void)device_set_driver(dev, NULL);<br>
&gt; -             device_sysctl_fini(dev);<br>
&gt; -             KASSERT(dev-&gt;busy == 0, (&quot;attach failed but busy&quot;));<br>
&gt; -             dev-&gt;state = DS_NOTPRESENT;<br>
&gt; +             if (disable_failed_devs) {<br>
&gt; +                     /*<br>
&gt; +                      * When the user has asked to disable failed devices, w<br>
&gt; e<br>
&gt; +                      * directly disable the device, but leave it in the<br>
&gt; +                      * attaching state. It will not try to probe/attach the<br>
&gt; +                      * device further. This leaves the device numbering<br>
&gt; +                      * intact for other similar devices in the system. It<br>
&gt; +                      * can be removed from this state with devctl.<br>
&gt; +                      */<br>
&gt; +                     device_disable(dev);<br>
&gt; +             } else {<br>
&gt; +                     /*<br>
&gt; +                      * Otherwise, when attach fails, tear down the state<br>
&gt; +                      * around that so we can retry when, for example, new<br>
&gt; +                      * drivers are loaded.<br>
&gt; +                      */<br>
&gt; +                     if (!(dev-&gt;flags &amp; DF_FIXEDCLASS))<br>
&gt; +                             devclass_delete_device(dev-&gt;devclass, dev);<br>
&gt; +                     (void)device_set_driver(dev, NULL);<br>
&gt; +                     device_sysctl_fini(dev);<br>
&gt; +                     KASSERT(dev-&gt;busy == 0, (&quot;attach failed but busy&quot;));<br>
&gt; +                     dev-&gt;state = DS_NOTPRESENT;<br>
&gt; +             }<br>
&gt;               return (error);<br>
&gt;       }<br>
&gt;       dev-&gt;flags |= DF_ATTACHED_ONCE;<br>
&gt;<br>
<br>
When switching a KVM console from a FreeBSD machine to another machine <br>
attached to the KVM the FreeBSD machine will panic. Photo attached.<br>
<br>
This probably needs an UPDATING entry explaining that <br>
hw.bus.disable_failed_devices sysctl/kenv must be zero (0) to avoid the <br>
panic.<br>
<br>
Sorry for taking so long to report this. Had an appointment this morning.<br>
<br>
<br>
Cheers,<br>
Cy Schubert &lt;<a href="mailto:Cy.Schubert@cschubert.com" target="_blank" rel="noreferrer">Cy.Schubert@cschubert.com</a>&gt;<br>
FreeBSD UNIX:  &lt;cy@FreeBSD.org&gt;   Web:  <a href="https://FreeBSD.org" rel="noreferrer noreferrer" target="_blank">https://FreeBSD.org</a><br>;
NTP:           &lt;<a href="mailto:cy@nwtime.org" target="_blank" rel="noreferrer">cy@nwtime.org</a>&gt;    Web:  <a href="https://nwtime.org" rel="noreferrer noreferrer" target="_blank">https://nwtime.org</a><br>;
<br>
                        e^(i*pi)+1=0<br>
</blockquote></div>

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANCZdfpiSYx3UK8zWpjQ1O3iOYFHHKLJuThN8RYAaLXm_YcNnA>