🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: muc.lists.netbsd.source-changes
12 messages
12 total messages Started by Taylor R Campbell Fri, 23 Oct 2026 02:23
Re: CVS commit: src/sys/dev/usb
#5
Author: Taylor R Campbell
Date: Fri, 23 Oct 2026 02:23
70 lines
4200 bytes
> Module Name:    src
> Committed By:   joe
> Date:           Thu Oct 22 17:17:47 UTC 2026
> 
> Modified Files:
>         src/sys/dev/usb: ohci.c
> 
> Log Message:
> use PR_ZERO on on pool allcoated memory and get rid of memset.
> 
> currently, xfer is zeroed using the wrong size.
> remove it and simplify code.

I think this change may not be correct.  I don't think pool_cache_get
respects PR_ZERO.  Perhaps we should add an assertion about this and
audit the system for it (or make it work by judiciously adding a
memset if PR_ZERO is passed).

I also suspect there was not a bug here before.  The code was
confusing because of the declared types, but correct:

--- ohci.c	31 Mar 2025 14:46:42 -0000	1.330
+++ ohci.c	22 Oct 2026 17:17:47 -0000	1.331
@@ -1112,14 +1112,12 @@ ohci_allocx(struct usbd_bus *bus, unsign
 	ohci_softc_t *sc = OHCI_BUS2SC(bus);
 	struct usbd_xfer *xfer;
 
-	xfer = pool_cache_get(sc->sc_xferpool, PR_WAITOK);
-	if (xfer != NULL) {
-		memset(xfer, 0, sizeof(struct ohci_xfer));
-
+	xfer = pool_cache_get(sc->sc_xferpool, PR_WAITOK | PR_ZERO);
 #ifdef DIAGNOSTIC
+	if (xfer != NULL) {
 		xfer->ux_state = XFER_BUSY;
-#endif
 	}
+#endif

Note that the declared type of xfer is struct usbd_xfer *, so with
this context it looks like memset(xfer, 0, sizeof(struct ohci_xfer))
is wrong and maybe should have been memset(xfer, 0, sizeof(*xfer)).

But the object allocated from sc->sc_xferpool actually sized for
struct ohci_xfer, so the original memset was fine:

	sc->sc_xferpool = pool_cache_init(sizeof(struct ohci_xfer), 0, 0, 0,
	    "ohcixfer", NULL, IPL_USB, NULL, NULL, NULL);

So I think this change did not fix a bug -- it actually _introduced_ a
bug by not zeroing the object, and should be reverted.

Perhaps we should rephrase this code to make it clearer (note that
pool_cache_get(sc->sc_xferpool PR_WAITOK) never fails, so there is no
need for a null test):

	struct ohci_xfer *ox;
	struct usbd_xfer *xfer;

	ox = pool_cache_get(sc->sc_xferpool, PR_WAITOK);
	memset(ox, 0, sizeof(*ox));
	xfer = &ox->xfer;
#ifdef DIAGNOSTIC
	xfer->ux_state = XFER_BUSY;
#endif
	return xfer;

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Re: CVS commit: src/sys/dev/usb
#9
Author: Jason Thorpe
Date: Fri, 23 Oct 2026 12:53
111 lines
10668 bytes
--Apple-Mail=_30471891-7FCA-4905-B028-C4986130A923
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=utf-8


> On Oct 22, 2026, at 7:23=E2=80=AFPM, Taylor R Campbell =
<riastradh@netbsd.org> wrote:
>=20
> I think this change may not be correct.  I don't think pool_cache_get
> respects PR_ZERO.  Perhaps we should add an assertion about this and
> audit the system for it (or make it work by judiciously adding a
> memset if PR_ZERO is passed).

pool_cache_get() is intended to return constructed objects.  I guess =
making it support PR_ZERO is OK so long as the cache doesn=E2=80=99t =
specify a constructor function, and should blow up on incompatible =
arguments if it does have one.

-- thorpej


--Apple-Mail=_30471891-7FCA-4905-B028-C4986130A923
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=utf-8

<html aria-label=3D"message body"><head><meta http-equiv=3D"content-type" =
content=3D"text/html; charset=3Dutf-8"></head><body =
style=3D"overflow-wrap: break-word; -webkit-nbsp-mode: space; =
line-break: after-white-space;"><br><div><blockquote type=3D"cite"><div>On=
 Oct 22, 2026, at 7:23=E2=80=AFPM, Taylor R Campbell =
&lt;riastradh@netbsd.org&gt; wrote:</div><br =
class=3D"Apple-interchange-newline"><div><meta charset=3D"UTF-8"><span =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: 400; =
letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration: none; float: none; =
display: inline !important;">I think this change may not be correct. =
&nbsp;I don't think pool_cache_get</span><br style=3D"caret-color: =
rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: =
normal; font-variant-caps: normal; font-weight: 400; letter-spacing: =
normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: =
none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration-line: none; =
text-decoration-thickness: auto; text-decoration-style: solid;"><span =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: 400; =
letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration: none; float: none; =
display: inline !important;">respects PR_ZERO. &nbsp;Perhaps we should =
add an assertion about this and</span><br style=3D"caret-color: rgb(0, =
0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
orphans: 2; text-align: start; text-indent: 0px; text-transform: none; =
white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration-line: none; =
text-decoration-thickness: auto; text-decoration-style: solid;"><span =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: 400; =
letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration: none; float: none; =
display: inline !important;">audit the system for it (or make it work by =
judiciously adding a</span><br style=3D"caret-color: rgb(0, 0, 0); =
font-family: Helvetica; font-size: 12px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
orphans: 2; text-align: start; text-indent: 0px; text-transform: none; =
white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration-line: none; =
text-decoration-thickness: auto; text-decoration-style: solid;"><span =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: 400; =
letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration: none; float: none; =
display: inline !important;">memset if PR_ZERO is passed).</span><br =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: 400; =
letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration-line: none; =
text-decoration-thickness: auto; text-decoration-style: =
solid;"></div></blockquote><br></div><div>pool_cache_get() is intended =
to return constructed objects. &nbsp;I guess making it support PR_ZERO =
is OK so long as the cache doesn=E2=80=99t specify a constructor =
function, and should blow up on incompatible arguments if it does have =
one.</div><br><div>
<span class=3D"Apple-style-span" style=3D"border-collapse: separate; =
color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; =
font-style: normal; font-variant: normal; font-weight: normal; =
letter-spacing: normal; line-height: normal; orphans: 2; text-align: =
auto; text-indent: 0px; text-transform: none; white-space: normal; =
widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; =
-webkit-border-vertical-spacing: 0px; =
-webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: =
auto; -webkit-text-stroke-width: 0px; "><div style=3D"word-wrap: =
break-word; -webkit-nbsp-mode: space; -webkit-line-break: =
after-white-space; ">-- thorpej</div></span>

</div>
<br></body></html>=

--Apple-Mail=_30471891-7FCA-4905-B028-C4986130A923--

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Re: CVS commit: src/sys/dev/usb
#6
Author: Taylor R Campbell
Date: Fri, 23 Oct 2026 15:33
29 lines
3189 bytes
> Date: Fri, 23 Oct 2026 05:53:38 -0700
> From: Jason Thorpe <thorpej@me.com>
> 
> > On Oct 22, 2026, at 7:23 PM, Taylor R Campbell <riastradh@netbsd.org> wrote:
> > 
> > I think this change may not be correct.  I don't think pool_cache_get
> > respects PR_ZERO.  Perhaps we should add an assertion about this and
> > audit the system for it (or make it work by judiciously adding a
> > memset if PR_ZERO is passed).
> 
> pool_cache_get() is intended to return constructed objects.  I guess
> making it support PR_ZERO is OK so long as the cache doesn't specify
> a constructor function, and should blow up on incompatible arguments
> if it does have one.

Maybe PR_ZERO should be an option to pool_cache_init rather than to
pool_cache_get?  (And pool_cache_get should assert that it is _not_
set.  Also pool_cache_init can assert that ctor/dtor is mutually
exclusive with PR_ZERO.)

Kind of unfortunate that the PR_* namespace is reused for five
different purposes (pool_init, pool_get, pool_cache_init,
pool_cache_get, and struct pool internal pr_flags), but at least the
numbers don't collide so we could do it.

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Re: CVS commit: src/sys/dev/usb
#14
Author: Jason Thorpe
Date: Fri, 23 Oct 2026 16:07
139 lines
11640 bytes
--Apple-Mail=_1BC5A5A0-949F-4BED-8D67-4E7D234B438D
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=utf-8



> On Oct 23, 2026, at 8:33=E2=80=AFAM, Taylor R Campbell =
<riastradh@NetBSD.org> wrote:
>=20
> Maybe PR_ZERO should be an option to pool_cache_init rather than to
> pool_cache_get?  (And pool_cache_get should assert that it is _not_
> set.  Also pool_cache_init can assert that ctor/dtor is mutually
> exclusive with PR_ZERO.)


Alternatively, there could be a magic constructor function value that =
could specify zero-on-allocate, since PR_ZERO and having a constructor =
are really mutually-exclusive. =20

int
pool_cache_ctor_zero(void *arg __unused, void *obj __unused, int flags =
__unused)
{
    return 0;
}

=E2=80=A6then in pool_cache_get_paddr(), before =E2=80=9Cobject=E2=80=9D =
is successfully returned:

    If (__predict_false(pc->pc_ctor =3D=3D pool_cache_ctor_zero) {
        memset(object, 0, pp->pp_pool->pr_reqsize);
  }

Could even specify a magic destructor if you want to zero-on-free (e.g. =
security-sensitive uses).

-- thorpej


--Apple-Mail=_1BC5A5A0-949F-4BED-8D67-4E7D234B438D
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=utf-8

<html aria-label=3D"message body"><head><meta http-equiv=3D"content-type" =
content=3D"text/html; charset=3Dutf-8"></head><body =
style=3D"overflow-wrap: break-word; -webkit-nbsp-mode: space; =
line-break: after-white-space;"><br =
id=3D"lineBreakAtBeginningOfMessage"><div><br><blockquote =
type=3D"cite"><div>On Oct 23, 2026, at 8:33=E2=80=AFAM, Taylor R =
Campbell &lt;riastradh@NetBSD.org&gt; wrote:</div><br =
class=3D"Apple-interchange-newline"><div><meta charset=3D"UTF-8"><span =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: 400; =
letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration: none; float: none; =
display: inline !important;">Maybe PR_ZERO should be an option to =
pool_cache_init rather than to</span><br style=3D"caret-color: rgb(0, 0, =
0); font-family: Helvetica; font-size: 12px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
orphans: 2; text-align: start; text-indent: 0px; text-transform: none; =
white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration-line: none; =
text-decoration-thickness: auto; text-decoration-style: solid;"><span =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: 400; =
letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration: none; float: none; =
display: inline !important;">pool_cache_get? &nbsp;(And pool_cache_get =
should assert that it is _not_</span><br style=3D"caret-color: rgb(0, 0, =
0); font-family: Helvetica; font-size: 12px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
orphans: 2; text-align: start; text-indent: 0px; text-transform: none; =
white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration-line: none; =
text-decoration-thickness: auto; text-decoration-style: solid;"><span =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: 400; =
letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration: none; float: none; =
display: inline !important;">set. &nbsp;Also pool_cache_init can assert =
that ctor/dtor is mutually</span><br style=3D"caret-color: rgb(0, 0, 0); =
font-family: Helvetica; font-size: 12px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
orphans: 2; text-align: start; text-indent: 0px; text-transform: none; =
white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration-line: none; =
text-decoration-thickness: auto; text-decoration-style: solid;"><span =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: 400; =
letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration: none; float: none; =
display: inline !important;">exclusive with PR_ZERO.)</span><br =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: 400; =
letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration-line: none; =
text-decoration-thickness: auto; text-decoration-style: =
solid;"></div></blockquote></div><div><br></div><div>Alternatively, =
there could be a magic constructor function value that could specify =
zero-on-allocate, since PR_ZERO and having a constructor are really =
mutually-exclusive. =
&nbsp;</div><div><br></div><div>int</div><div>pool_cache_ctor_zero(void =
*arg __unused, void *obj __unused, int flags =
__unused)</div><div>{</div><div>&nbsp; &nbsp; return =
0;</div><div>}</div><div><br></div><div>=E2=80=A6then in =
pool_cache_get_paddr(), before =E2=80=9Cobject=E2=80=9D is successfully =
returned:</div><div><br></div><div>&nbsp; &nbsp; If =
(__predict_false(pc-&gt;pc_ctor =3D=3D pool_cache_ctor_zero) =
{</div><div>&nbsp; &nbsp; &nbsp; &nbsp; memset(object, 0, =
pp-&gt;pp_pool-&gt;<font face=3D"Menlo"><span style=3D"font-size: =
11px;">pr_reqsize);</span></font></div><div><font face=3D"Menlo"><span =
style=3D"font-size: 11px;">&nbsp; =
}</span></font></div><div><br></div><div>Could even specify a magic =
destructor if you want to zero-on-free (e.g. security-sensitive =
uses).</div><br><div>
<span class=3D"Apple-style-span" style=3D"border-collapse: separate; =
font-variant-ligatures: normal; font-variant-alternates: normal; =
font-variant-numeric: normal; font-variant-east-asian: normal; =
font-variant-position: normal; font-weight: normal; line-height: normal; =
border-spacing: 0px; -webkit-text-decorations-in-effect: none;"><div =
style=3D"word-wrap: break-word; -webkit-nbsp-mode: space; =
-webkit-line-break: after-white-space; ">-- thorpej</div></span>

</div>
<br></body></html>=

--Apple-Mail=_1BC5A5A0-949F-4BED-8D67-4E7D234B438D--

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Re: CVS commit: src/sys/dev/usb
#7
Author: Taylor R Campbell
Date: Fri, 23 Oct 2026 16:37
41 lines
3496 bytes
> Date: Fri, 23 Oct 2026 09:07:24 -0700
> From: Jason Thorpe <thorpej@me.com>
> 
> > On Oct 23, 2026, at 8:33 AM, Taylor R Campbell <riastradh@NetBSD.org> wrote:
> > 
> > Maybe PR_ZERO should be an option to pool_cache_init rather than to
> > pool_cache_get?  (And pool_cache_get should assert that it is _not_
> > set.  Also pool_cache_init can assert that ctor/dtor is mutually
> > exclusive with PR_ZERO.)
> 
> Alternatively, there could be a magic constructor function value that could specify zero-on-allocate, since PR_ZERO and having a constructor are really mutually-exclusive.  
> 
> int
> pool_cache_ctor_zero(void *arg __unused, void *obj __unused, int flags __unused)
> {
>     return 0;
> }
> 
> …then in pool_cache_get_paddr(), before “object” is successfully returned:
> 
>     If (__predict_false(pc->pc_ctor == pool_cache_ctor_zero) {
>         memset(object, 0, pp->pp_pool->pr_reqsize);
>   }
> 
> Could even specify a magic destructor if you want to zero-on-free (e.g. security-sensitive uses).

I think a flag is clearer than a magic ctor/dtor.  The point here is
to change the behaviour of pool_cache_get (or pool_cache_put), but the
ctor/dtor explicitly _do not generally_ run on pool_cache_get/put (a
common misunderstanding I have seen, and had myself in the past).
Using them for this role seems likely to be even more confusing.

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Re: CVS commit: src/sys/dev/usb
#11
Author: Jason Thorpe
Date: Fri, 23 Oct 2026 16:48
128 lines
11737 bytes
--Apple-Mail=_65C01AA3-1B81-42FC-AA60-BBF82B89DDB5
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=utf-8



> On Oct 23, 2026, at 9:37=E2=80=AFAM, Taylor R Campbell =
<riastradh@NetBSD.org> wrote:
>=20
> I think a flag is clearer than a magic ctor/dtor.  The point here is
> to change the behaviour of pool_cache_get (or pool_cache_put), but the
> ctor/dtor explicitly _do not generally_ run on pool_cache_get/put (a
> common misunderstanding I have seen, and had myself in the past).
> Using them for this role seems likely to be even more confusing.


Counter-argument: Use of a ctor guarantees that the object will be =
returned to the caller in the constructed state.  The only difference =
with the =E2=80=9Czero=E2=80=9D constructor is when it has to be called =
in order to make that guarantee.

-- thorpej


--Apple-Mail=_65C01AA3-1B81-42FC-AA60-BBF82B89DDB5
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=utf-8

<html aria-label=3D"message body"><head><meta http-equiv=3D"content-type" =
content=3D"text/html; charset=3Dutf-8"></head><body =
style=3D"overflow-wrap: break-word; -webkit-nbsp-mode: space; =
line-break: after-white-space;"><br =
id=3D"lineBreakAtBeginningOfMessage"><div><br><blockquote =
type=3D"cite"><div>On Oct 23, 2026, at 9:37=E2=80=AFAM, Taylor R =
Campbell &lt;riastradh@NetBSD.org&gt; wrote:</div><div><br =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: 400; =
letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration-line: none; =
text-decoration-thickness: auto; text-decoration-style: solid;"><span =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: 400; =
letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration: none; float: none; =
display: inline !important;">I think a flag is clearer than a magic =
ctor/dtor. &nbsp;The point here is</span><br style=3D"caret-color: =
rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: =
normal; font-variant-caps: normal; font-weight: 400; letter-spacing: =
normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: =
none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration-line: none; =
text-decoration-thickness: auto; text-decoration-style: solid;"><span =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: 400; =
letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration: none; float: none; =
display: inline !important;">to change the behaviour of pool_cache_get =
(or pool_cache_put), but the</span><br style=3D"caret-color: rgb(0, 0, =
0); font-family: Helvetica; font-size: 12px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
orphans: 2; text-align: start; text-indent: 0px; text-transform: none; =
white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration-line: none; =
text-decoration-thickness: auto; text-decoration-style: solid;"><span =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: 400; =
letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration: none; float: none; =
display: inline !important;">ctor/dtor explicitly _do not generally_ run =
on pool_cache_get/put (a</span><br style=3D"caret-color: rgb(0, 0, 0); =
font-family: Helvetica; font-size: 12px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
orphans: 2; text-align: start; text-indent: 0px; text-transform: none; =
white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration-line: none; =
text-decoration-thickness: auto; text-decoration-style: solid;"><span =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: 400; =
letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration: none; float: none; =
display: inline !important;">common misunderstanding I have seen, and =
had myself in the past).</span><br style=3D"caret-color: rgb(0, 0, 0); =
font-family: Helvetica; font-size: 12px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
orphans: 2; text-align: start; text-indent: 0px; text-transform: none; =
white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration-line: none; =
text-decoration-thickness: auto; text-decoration-style: solid;"><span =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: 400; =
letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration: none; float: none; =
display: inline !important;">Using them for this role seems likely to be =
even more =
confusing.</span></div></blockquote></div><div><br></div><div>Counter-argu=
ment: Use of a ctor guarantees that the object will be returned to the =
caller in the constructed state. &nbsp;The only difference with the =
=E2=80=9Czero=E2=80=9D constructor is when it has to be called in order =
to make that guarantee.</div><br><div>
<span class=3D"Apple-style-span" style=3D"border-collapse: separate; =
color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; =
font-style: normal; font-variant: normal; font-weight: normal; =
letter-spacing: normal; line-height: normal; orphans: 2; text-align: =
auto; text-indent: 0px; text-transform: none; white-space: normal; =
widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; =
-webkit-border-vertical-spacing: 0px; =
-webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: =
auto; -webkit-text-stroke-width: 0px; "><div style=3D"word-wrap: =
break-word; -webkit-nbsp-mode: space; -webkit-line-break: =
after-white-space; ">-- thorpej</div></span>

</div>
<br></body></html>=

--Apple-Mail=_65C01AA3-1B81-42FC-AA60-BBF82B89DDB5--

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Re: CVS commit: src/sys/dev/usb
#12
Author: Jason Thorpe
Date: Fri, 23 Oct 2026 16:56
73 lines
7781 bytes
--Apple-Mail=_C147AB54-D9D7-4E37-AACB-555E1E059C28
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=utf-8


> On Oct 23, 2026, at 9:48=E2=80=AFAM, Jason Thorpe <thorpej@me.com> =
wrote:
>=20
> Counter-argument: Use of a ctor guarantees that the object will be =
returned to the caller in the constructed state.  The only difference =
with the =E2=80=9Czero=E2=80=9D constructor is when it has to be called =
in order to make that guarantee.

Ok, =E2=80=9Cguarantees=E2=80=9D is maybe too strong of a statement.  =
Part of the pool_cache API contract is that, when using a constructor, =
you=E2=80=99ll also put things back into the cache in a valid =
constructed state (this is the same behavior as Solaris=E2=80=99s =
kmem_cache).

But I don=E2=80=99t think that invalidates my argument here.  It=E2=80=99s=
 still part of the API contract that pool_cache_get() returns a =
constructed object.

-- thorpej


--Apple-Mail=_C147AB54-D9D7-4E37-AACB-555E1E059C28
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=utf-8

<html aria-label=3D"message body"><head><meta http-equiv=3D"content-type" =
content=3D"text/html; charset=3Dutf-8"></head><body =
style=3D"overflow-wrap: break-word; -webkit-nbsp-mode: space; =
line-break: after-white-space;"><br><div><blockquote type=3D"cite"><div>On=
 Oct 23, 2026, at 9:48=E2=80=AFAM, Jason Thorpe &lt;thorpej@me.com&gt; =
wrote:</div><div><div style=3D"overflow-wrap: break-word; =
-webkit-nbsp-mode: space; line-break: =
after-white-space;"><br><div>Counter-argument: Use of a ctor guarantees =
that the object will be returned to the caller in the constructed state. =
&nbsp;The only difference with the =E2=80=9Czero=E2=80=9D constructor is =
when it has to be called in order to make that =
guarantee.</div></div></div></blockquote><div><br></div><div>Ok, =
=E2=80=9Cguarantees=E2=80=9D is maybe too strong of a statement. =
&nbsp;Part of the pool_cache API contract is that, when using a =
constructor, you=E2=80=99ll also put things back into the cache in a =
valid constructed state (this is the same behavior as Solaris=E2=80=99s =
kmem_cache).</div><div><br></div><div>But I don=E2=80=99t think that =
invalidates my argument here. &nbsp;It=E2=80=99s still part of the API =
contract that pool_cache_get() returns a constructed =
object.</div></div><br><div>
<span class=3D"Apple-style-span" style=3D"border-collapse: separate; =
color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; =
font-style: normal; font-variant: normal; font-weight: normal; =
letter-spacing: normal; line-height: normal; orphans: 2; text-align: =
auto; text-indent: 0px; text-transform: none; white-space: normal; =
widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; =
-webkit-border-vertical-spacing: 0px; =
-webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: =
auto; -webkit-text-stroke-width: 0px; "><div style=3D"word-wrap: =
break-word; -webkit-nbsp-mode: space; -webkit-line-break: =
after-white-space; ">-- thorpej</div></span>

</div>
<br></body></html>=

--Apple-Mail=_C147AB54-D9D7-4E37-AACB-555E1E059C28--

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Re: CVS commit: src/sys/dev/usb
#8
Author: Taylor R Campbell
Date: Fri, 23 Oct 2026 17:33
44 lines
3386 bytes
> Date: Fri, 23 Oct 2026 09:48:40 -0700
> From: Jason Thorpe <thorpej@me.com>
> 
> > On Oct 23, 2026, at 9:37 AM, Taylor R Campbell <riastradh@NetBSD.org> wrote:
> > 
> > I think a flag is clearer than a magic ctor/dtor.  The point here is
> > to change the behaviour of pool_cache_get (or pool_cache_put), but the
> > ctor/dtor explicitly _do not generally_ run on pool_cache_get/put (a
> > common misunderstanding I have seen, and had myself in the past).
> > Using them for this role seems likely to be even more confusing.
> 
> Counter-argument: Use of a ctor guarantees that the object will be
> returned to the caller in the constructed state.

No, it doesn't?

Given

	ctor(obj) { obj->foo = 1; }

the following can print either 1 or 2:

	obj = pool_cache_get(pc);
	obj->foo = 2;
	pool_cache_put(pc, obj);

	obj = pool_cache_get(pc);
	printf("%d\n", obj->foo);

There _may_ be a dtor/ctor cycle between the pool_cache_put and the
pool_cache_get, but there's no _guarantee_ of that.

The only guarantee is that when a _backing page_ is allocated, the
ctor will run before pool_cache_get returns any objects from it, and
after pool_cache_put, the dtor will run before its _backing page_ is
freed.

In contrast, the proposal with PR_ZERO is to guarantee that it prints
0, every time.

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Re: CVS commit: src/sys/dev/usb
#10
Author: Jason Thorpe
Date: Fri, 23 Oct 2026 17:51
79 lines
8339 bytes
--Apple-Mail=_F102D36C-17B8-4479-A087-0D0781755D21
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=utf-8



> On Oct 23, 2026, at 10:33=E2=80=AFAM, Taylor R Campbell =
<riastradh@netbsd.org> wrote:
>=20
> There _may_ be a dtor/ctor cycle between the pool_cache_put and the
> pool_cache_get, but there's no _guarantee_ of that.

Right, see my follow-up message.

-- thorpej


--Apple-Mail=_F102D36C-17B8-4479-A087-0D0781755D21
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=utf-8

<html aria-label=3D"message body"><head><meta http-equiv=3D"content-type" =
content=3D"text/html; charset=3Dutf-8"></head><body =
style=3D"overflow-wrap: break-word; -webkit-nbsp-mode: space; =
line-break: after-white-space;"><br =
id=3D"lineBreakAtBeginningOfMessage"><div><br><blockquote =
type=3D"cite"><div>On Oct 23, 2026, at 10:33=E2=80=AFAM, Taylor R =
Campbell &lt;riastradh@netbsd.org&gt; wrote:</div><br =
class=3D"Apple-interchange-newline"><div><span style=3D"caret-color: =
rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: =
normal; font-variant-caps: normal; font-weight: 400; letter-spacing: =
normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: =
none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration: none; float: none; =
display: inline !important;">There _may_ be a dtor/ctor cycle between =
the pool_cache_put and the</span><br style=3D"caret-color: rgb(0, 0, 0); =
font-family: Helvetica; font-size: 12px; font-style: normal; =
font-variant-caps: normal; font-weight: 400; letter-spacing: normal; =
orphans: 2; text-align: start; text-indent: 0px; text-transform: none; =
white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration-line: none; =
text-decoration-thickness: auto; text-decoration-style: solid;"><span =
style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant-caps: normal; font-weight: 400; =
letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; =
text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-text-stroke-width: 0px; text-decoration: none; float: none; =
display: inline !important;">pool_cache_get, but there's no _guarantee_ =
of that.</span><br style=3D"caret-color: rgb(0, 0, 0); font-family: =
Helvetica; font-size: 12px; font-style: normal; font-variant-caps: =
normal; font-weight: 400; letter-spacing: normal; orphans: 2; =
text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
text-decoration-line: none; text-decoration-thickness: auto; =
text-decoration-style: solid;"></div></blockquote><br></div><div>Right, =
see my follow-up message.</div><br><div>
<span class=3D"Apple-style-span" style=3D"border-collapse: separate; =
color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; =
font-style: normal; font-variant: normal; font-weight: normal; =
letter-spacing: normal; line-height: normal; orphans: 2; text-align: =
auto; text-indent: 0px; text-transform: none; white-space: normal; =
widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; =
-webkit-border-vertical-spacing: 0px; =
-webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: =
auto; -webkit-text-stroke-width: 0px; "><div style=3D"word-wrap: =
break-word; -webkit-nbsp-mode: space; -webkit-line-break: =
after-white-space; ">-- thorpej</div></span>

</div>
<br></body></html>=

--Apple-Mail=_F102D36C-17B8-4479-A087-0D0781755D21--

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Re: CVS commit: src/sys/dev/usb
#13
Author: Greg Troxel
Date: Sat, 24 Oct 2026 14:37
29 lines
2844 bytes
Jason Thorpe <thorpej@me.com> writes:

>> On Oct 22, 2026, at 7:23 PM, Taylor R Campbell <riastradh@netbsd.org> wrote:
>> 
>> I think this change may not be correct.  I don't think pool_cache_get
>> respects PR_ZERO.  Perhaps we should add an assertion about this and
>> audit the system for it (or make it work by judiciously adding a
>> memset if PR_ZERO is passed).
>
> pool_cache_get() is intended to return constructed objects.  I guess making it support PR_ZERO is OK so long as the cache doesn’t specify a constructor function, and should blow up on incompatible arguments if it does have one.

That's a really good point.  I had forgotten the wisdom of the original
papers.

I wonder if it's basically an error to have a pool cache without a
constructor (semantically).    I suppose "all zeros if there is no
constructor" is perhaps a reasonable sort-of-constructor, as in "safe
state before real construction".

What does openindiana/illumos  do here?


--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Re: CVS commit: src/sys/dev/usb
#15
Author: Jason Thorpe
Date: Sat, 24 Oct 2026 14:46
26 lines
5360 bytes
> On Oct 24, 2026, at 10:37 AM, Greg Troxel <gdt@lexort.com> wrote:
> 
> I wonder if it's basically an error to have a pool cache without a
> constructor (semantically).    I suppose "all zeros if there is no
> constructor" is perhaps a reasonable sort-of-constructor, as in "safe
> state before real construction".
> 
> What does openindiana/illumos  do here?

It is not an error to not use a constructor -<em-dash>- esp considering that the general memory allocator is built on top of pool_cache.

IIRC, the original Solaris behavior was “uninitialized if no constructor specified”.  I would not advocate for “always zero-init if no constructor” because that could be wasteful.  I’d rather have it be an explicit ask when the pool_cache is initialized.

-- thorpej


--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Re: CVS commit: src/sys/dev/usb
#16
Author: Greg Troxel
Date: Sat, 24 Oct 2026 17:32
21 lines
2508 bytes
Jason Thorpe <thorpej@me.com> writes:

>> What does openindiana/illumos  do here?
>
> It is not an error to not use a constructor -<em-dash>- esp considering that the general memory allocator is built on top of pool_cache.
>
> IIRC, the original Solaris behavior was “uninitialized if no
> constructor specified”.  I would not advocate for “always zero-init if
> no constructor” because that could be wasteful.  I’d rather have it be
> an explicit ask when the pool_cache is initialized.

That sounds reasonable.   It seems like asking for zero and a
constructor should KASSERT and if not DIAGNOSTIC be an error.


--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads