Date: Thu, 6 Mar 2025 19:34:41 +0800 From: Zhenlei Huang <zlei@FreeBSD.org> To: Mateusz Guzik <mjg@FreeBSD.org> Cc: "src-committers@freebsd.org" <src-committers@FreeBSD.org>, "dev-commits-src-all@freebsd.org" <dev-commits-src-all@FreeBSD.org>, Warner Losh <imp@freebsd.org>, "dev-commits-src-main@freebsd.org" <dev-commits-src-main@FreeBSD.org> Subject: Re: git: 234683726708 - main - devclass: make devclass_alloc_unit use M_NOWAIT Message-ID: <6BE51FFD-DE19-42E6-B115-354BB74B4D78@FreeBSD.org> In-Reply-To: <F1B3652E-0D0C-402A-8509-D510992DAC15@FreeBSD.org> References: <202503061103.526B32Id022652@gitrepo.freebsd.org> <F1B3652E-0D0C-402A-8509-D510992DAC15@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--Apple-Mail=_21A3F846-4569-4526-B2CD-C22C6384E294 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On Mar 6, 2025, at 7:32 PM, Zhenlei Huang <zlei@FreeBSD.org> wrote: >=20 >=20 >=20 >> On Mar 6, 2025, at 7:03 PM, Mateusz Guzik <mjg@FreeBSD.org = <mailto:mjg@FreeBSD.org>> wrote: >>=20 >> The branch main has been updated by mjg: >>=20 >> URL: = https://cgit.FreeBSD.org/src/commit/?id=3D234683726708cf5212d672d676d30056= d4133859 = <https://cgit.freebsd.org/src/commit/?id=3D234683726708cf5212d672d676d3005= 6d4133859> >>=20 >> commit 234683726708cf5212d672d676d30056d4133859 >> Author: Mateusz Guzik <mjg@FreeBSD.org <mailto:mjg@FreeBSD.org>> >> AuthorDate: 2025-03-06 11:01:49 +0000 >> Commit: Mateusz Guzik <mjg@FreeBSD.org <mailto:mjg@FreeBSD.org>> >> CommitDate: 2025-03-06 11:01:49 +0000 >>=20 >> devclass: make devclass_alloc_unit use M_NOWAIT >>=20 >> The only caller already does this. >>=20 >> The routine can be called with a mutex held making M_WAITOK = illegal. >>=20 >> Sponsored by: Rubicon Communications, LLC ("Netgate") >> --- >> sys/kern/subr_bus.c | 8 ++++++-- >> 1 file changed, 6 insertions(+), 2 deletions(-) >>=20 >> diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c >> index 9506e471705c..0422352bba51 100644 >> --- a/sys/kern/subr_bus.c >> +++ b/sys/kern/subr_bus.c >> @@ -1208,6 +1208,7 @@ devclass_get_sysctl_tree(devclass_t dc) >> static int >> devclass_alloc_unit(devclass_t dc, device_t dev, int *unitp) >> { >> + device_t *devices; >> const char *s; >> int unit =3D *unitp; >>=20 >> @@ -1264,8 +1265,11 @@ devclass_alloc_unit(devclass_t dc, device_t = dev, int *unitp) >> int newsize; >>=20 >> newsize =3D unit + 1; >> - dc->devices =3D reallocf(dc->devices, >> - newsize * sizeof(*dc->devices), M_BUS, M_WAITOK); >> + devices =3D reallocf(dc->devices, >> + newsize * sizeof(*dc->devices), M_BUS, M_NOWAIT); >=20 > I'd recommend against this. =46rom the commit message of f3d3c63442ff, = Warner said, > > In addition, transition to M_WAITOK since this is a sleepable = context > So, the M_WAITOK is intentional. >=20 > Rather than reverting this, the caller devclass_add_device() should = use M_WAITOK. >=20 > ``` > - dev->nameunit =3D malloc(buflen, M_BUS, M_NOWAIT|M_ZERO); > - if (!dev->nameunit) > - return (ENOMEM); > + dev->nameunit =3D malloc(buflen, M_BUS, M_WAITOK | M_ZERO); > ``` Emm, sorry for the noise. I missed the commit message, > The routine can be called with a mutex held making M_WAITOK illegal. >=20 > Best regards, > Zhenlei >=20 >> + if (devices =3D=3D NULL) >> + return (ENOMEM); >> + dc->devices =3D devices; >> memset(dc->devices + dc->maxunit, 0, >> sizeof(device_t) * (newsize - dc->maxunit)); >> dc->maxunit =3D newsize; --Apple-Mail=_21A3F846-4569-4526-B2CD-C22C6384E294 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii <html><head><meta http-equiv=3D"Content-Type" content=3D"text/html; = charset=3Dus-ascii"></head><body style=3D"word-wrap: break-word; = -webkit-nbsp-mode: space; line-break: after-white-space;" class=3D""><br = class=3D""><div><br class=3D""><blockquote type=3D"cite" class=3D""><div = class=3D"">On Mar 6, 2025, at 7:32 PM, Zhenlei Huang <<a = href=3D"mailto:zlei@FreeBSD.org" class=3D"">zlei@FreeBSD.org</a>> = wrote:</div><br class=3D"Apple-interchange-newline"><div class=3D""><meta = charset=3D"UTF-8" class=3D""><div style=3D"caret-color: rgb(0, 0, 0); = font-family: Helvetica; font-size: 13px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = text-align: start; text-indent: 0px; text-transform: none; white-space: = normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; = text-decoration: none;" class=3D""><br = class=3D"Apple-interchange-newline"><br class=3D""><blockquote = type=3D"cite" class=3D""><div class=3D"">On Mar 6, 2025, at 7:03 PM, = Mateusz Guzik <<a href=3D"mailto:mjg@FreeBSD.org" = class=3D"">mjg@FreeBSD.org</a>> wrote:</div><br = class=3D"Apple-interchange-newline"><div class=3D""><div class=3D"">The = branch main has been updated by mjg:<br class=3D""><br = class=3D"">URL:<span class=3D"Apple-converted-space"> </span><a = href=3D"https://cgit.freebsd.org/src/commit/?id=3D234683726708cf5212d672d6= 76d30056d4133859" = class=3D"">https://cgit.FreeBSD.org/src/commit/?id=3D234683726708cf5212d67= 2d676d30056d4133859</a><br class=3D""><br class=3D"">commit = 234683726708cf5212d672d676d30056d4133859<br class=3D"">Author: = Mateusz Guzik <<a = href=3D"mailto:mjg@FreeBSD.org" class=3D"">mjg@FreeBSD.org</a>><br = class=3D"">AuthorDate: 2025-03-06 11:01:49 +0000<br class=3D"">Commit: = Mateusz Guzik <<a = href=3D"mailto:mjg@FreeBSD.org" class=3D"">mjg@FreeBSD.org</a>><br = class=3D"">CommitDate: 2025-03-06 11:01:49 +0000<br class=3D""><br = class=3D""> devclass: make devclass_alloc_unit use = M_NOWAIT<br class=3D""><br class=3D""> The only caller = already does this.<br class=3D""><br class=3D""> The = routine can be called with a mutex held making M_WAITOK illegal.<br = class=3D""><br class=3D""> Sponsored by: = Rubicon Communications, LLC ("Netgate")<br class=3D"">---<br = class=3D"">sys/kern/subr_bus.c | 8 ++++++--<br class=3D"">1 file = changed, 6 insertions(+), 2 deletions(-)<br class=3D""><br class=3D"">diff= --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c<br class=3D"">index = 9506e471705c..0422352bba51 100644<br class=3D"">--- = a/sys/kern/subr_bus.c<br class=3D"">+++ b/sys/kern/subr_bus.c<br = class=3D"">@@ -1208,6 +1208,7 @@ devclass_get_sysctl_tree(devclass_t = dc)<br class=3D"">static int<br class=3D"">devclass_alloc_unit(devclass_t = dc, device_t dev, int *unitp)<br class=3D"">{<br class=3D"">+<span = class=3D"Apple-tab-span" style=3D"white-space: pre;"> </span>device_t = *devices;<br class=3D""><span class=3D"Apple-tab-span" = style=3D"white-space: pre;"> </span>const char *s;<br class=3D""><span = class=3D"Apple-tab-span" style=3D"white-space: pre;"> </span>int unit = =3D *unitp;<br class=3D""><br class=3D"">@@ -1264,8 +1265,11 @@ = devclass_alloc_unit(devclass_t dc, device_t dev, int *unitp)<br = class=3D""><span class=3D"Apple-tab-span" style=3D"white-space: pre;"> = </span><span class=3D"Apple-tab-span" style=3D"white-space: pre;"> = </span>int newsize;<br class=3D""><br class=3D""><span = class=3D"Apple-tab-span" style=3D"white-space: pre;"> </span><span = class=3D"Apple-tab-span" style=3D"white-space: pre;"> </span>newsize =3D= unit + 1;<br class=3D"">-<span class=3D"Apple-tab-span" = style=3D"white-space: pre;"> </span><span class=3D"Apple-tab-span" = style=3D"white-space: pre;"> </span>dc->devices =3D = reallocf(dc->devices,<br class=3D"">-<span class=3D"Apple-tab-span" = style=3D"white-space: pre;"> </span><span class=3D"Apple-tab-span" = style=3D"white-space: pre;"> </span><span = class=3D"Apple-converted-space"> </span> newsize * = sizeof(*dc->devices), M_BUS, M_WAITOK);<br class=3D"">+<span = class=3D"Apple-tab-span" style=3D"white-space: pre;"> </span><span = class=3D"Apple-tab-span" style=3D"white-space: pre;"> </span>devices =3D= reallocf(dc->devices,<br class=3D"">+<span class=3D"Apple-tab-span" = style=3D"white-space: pre;"> </span><span class=3D"Apple-tab-span" = style=3D"white-space: pre;"> </span><span = class=3D"Apple-converted-space"> </span> newsize * = sizeof(*dc->devices), M_BUS, M_NOWAIT);<br = class=3D""></div></div></blockquote><div class=3D""><br = class=3D""></div>I'd recommend against this. =46rom the commit message = of f3d3c63442ff, Warner said,</div><div style=3D"caret-color: rgb(0, 0, = 0); font-family: Helvetica; font-size: 13px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = text-align: start; text-indent: 0px; text-transform: none; white-space: = normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; = text-decoration: none;" class=3D"">> In addition, transition to = M_WAITOK since this is a sleepable context</div><div style=3D"caret-color:= rgb(0, 0, 0); font-family: Helvetica; font-size: 13px; font-style: = normal; font-variant-caps: normal; font-weight: 400; letter-spacing: = normal; text-align: start; text-indent: 0px; text-transform: none; = white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; = text-decoration: none;" class=3D"">So, the M_WAITOK is = intentional.</div><div style=3D"caret-color: rgb(0, 0, 0); font-family: = Helvetica; font-size: 13px; font-style: normal; font-variant-caps: = normal; font-weight: 400; letter-spacing: normal; text-align: start; = text-indent: 0px; text-transform: none; white-space: normal; = word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: = none;" class=3D""><br class=3D""></div><div style=3D"caret-color: rgb(0, = 0, 0); font-family: Helvetica; font-size: 13px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = text-align: start; text-indent: 0px; text-transform: none; white-space: = normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; = text-decoration: none;" class=3D"">Rather than reverting this, the = caller devclass_add_device() should use<span = class=3D"Apple-converted-space"> </span><span class=3D"" = style=3D"caret-color: rgb(0, 0, 0);">M_WAITOK.</span></div><div = style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: = 13px; font-style: normal; font-variant-caps: normal; font-weight: 400; = letter-spacing: normal; text-align: start; text-indent: 0px; = text-transform: none; white-space: normal; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration: none;" class=3D""><span = class=3D"" style=3D"caret-color: rgb(0, 0, 0);"><br = class=3D""></span></div><div style=3D"caret-color: rgb(0, 0, 0); = font-family: Helvetica; font-size: 13px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = text-align: start; text-indent: 0px; text-transform: none; white-space: = normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; = text-decoration: none;" class=3D""><span class=3D"" style=3D"caret-color: = rgb(0, 0, 0);">```</span></div><div style=3D"caret-color: rgb(0, 0, 0); = font-family: Helvetica; font-size: 13px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = text-align: start; text-indent: 0px; text-transform: none; white-space: = normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; = text-decoration: none;" class=3D""><div class=3D""><font class=3D""><span = class=3D"" style=3D"caret-color: rgb(0, 0, 0);">- = dev->nameunit =3D malloc(buflen, M_BUS, = M_NOWAIT|M_ZERO);</span></font></div><div class=3D""><font = class=3D""><span class=3D"" style=3D"caret-color: rgb(0, 0, 0);">- = if (!dev->nameunit)</span></font></div><div = class=3D""><font class=3D""><span class=3D"" style=3D"caret-color: = rgb(0, 0, 0);">- return = (ENOMEM);</span></font></div><div class=3D""><font class=3D""><span = class=3D"" style=3D"caret-color: rgb(0, 0, 0);">+ = dev->nameunit =3D malloc(buflen, M_BUS, M_WAITOK | = M_ZERO);</span></font></div></div><div style=3D"caret-color: rgb(0, 0, = 0); font-family: Helvetica; font-size: 13px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = text-align: start; text-indent: 0px; text-transform: none; white-space: = normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; = text-decoration: none;" class=3D""><span class=3D"" style=3D"caret-color: = rgb(0, 0, 0);">```</span></div></div></blockquote><div><br = class=3D""></div><div>Emm, sorry for the noise. I missed the commit = message,</div><div>> The routine can be called with a mutex held = making M_WAITOK illegal.</div><br class=3D""><blockquote type=3D"cite" = class=3D""><div class=3D""><div style=3D"caret-color: rgb(0, 0, 0); = font-family: Helvetica; font-size: 13px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = text-align: start; text-indent: 0px; text-transform: none; white-space: = normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; = text-decoration: none;" class=3D""><span class=3D"" style=3D"caret-color: = rgb(0, 0, 0);"><br class=3D""></span></div><div style=3D"caret-color: = rgb(0, 0, 0); font-family: Helvetica; font-size: 13px; font-style: = normal; font-variant-caps: normal; font-weight: 400; letter-spacing: = normal; text-align: start; text-indent: 0px; text-transform: none; = white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; = text-decoration: none;" class=3D""><div style=3D"caret-color: rgb(0, 0, = 0);" class=3D"">Best regards,</div><div style=3D"caret-color: rgb(0, 0, = 0);" class=3D"">Zhenlei</div></div><div style=3D"caret-color: rgb(0, 0, = 0); font-family: Helvetica; font-size: 13px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = text-align: start; text-indent: 0px; text-transform: none; white-space: = normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; = text-decoration: none;" class=3D""><br class=3D""><blockquote = type=3D"cite" class=3D""><div class=3D""><div class=3D"">+<span = class=3D"Apple-tab-span" style=3D"white-space: pre;"> </span><span = class=3D"Apple-tab-span" style=3D"white-space: pre;"> </span>if = (devices =3D=3D NULL)<br class=3D"">+<span class=3D"Apple-tab-span" = style=3D"white-space: pre;"> </span><span class=3D"Apple-tab-span" = style=3D"white-space: pre;"> </span><span class=3D"Apple-tab-span" = style=3D"white-space: pre;"> </span>return (ENOMEM);<br = class=3D"">+<span class=3D"Apple-tab-span" style=3D"white-space: pre;"> = </span><span class=3D"Apple-tab-span" style=3D"white-space: pre;"> = </span>dc->devices =3D devices;<br class=3D""><span = class=3D"Apple-tab-span" style=3D"white-space: pre;"> </span><span = class=3D"Apple-tab-span" style=3D"white-space: pre;"> = </span>memset(dc->devices + dc->maxunit, 0,<br class=3D""><span = class=3D"Apple-tab-span" style=3D"white-space: pre;"> </span><span = class=3D"Apple-tab-span" style=3D"white-space: pre;"> </span><span = class=3D"Apple-converted-space"> </span> sizeof(devi= ce_t) * (newsize - dc->maxunit));<br class=3D""><span = class=3D"Apple-tab-span" style=3D"white-space: pre;"> </span><span = class=3D"Apple-tab-span" style=3D"white-space: pre;"> = </span>dc->maxunit =3D = newsize;</div></div></blockquote></div></div></blockquote></div><br = class=3D""><div class=3D""> <div><br class=3D""></div> </div> <br class=3D""></body></html>= --Apple-Mail=_21A3F846-4569-4526-B2CD-C22C6384E294--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6BE51FFD-DE19-42E6-B115-354BB74B4D78>