From nobody Thu Mar 06 11:32:02 2025 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 4Z7nMH68vzz5pS4L; Thu, 06 Mar 2025 11:32:11 +0000 (UTC) (envelope-from zlei@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (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 "smtp.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Z7nMH2dWPz3rCf; Thu, 06 Mar 2025 11:32:11 +0000 (UTC) (envelope-from zlei@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1741260731; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=sArnxEZ3utMyaYzKvo18hubCF9ygEcfBZBWhTgosCxA=; b=t2LEzzSVGjJvce71P26TgAFZByPkfncwmpzNnH9ixU6JSTlt8Tmq3CcT1/GsyE1RNSXex8 HNNUYF4Y2vknXg5F94lWr3dKlWboqRxXfyhY58HehcmTDX8UVlKOh27P9LTbJOL13PNZZ8 TKHyA0LU+IsljMryorSRgGOQHt8vqaeLoj739GmlegPo+2pmqZ7h7mjCpbAaKmbU4OH9g4 5QroV8/QqblE9YDRKwfWY17ow9YcqAnXCQ4EC5ygiryNRGdjMpay8OwOw5A36egq2pnEGe MU85ZqNzxh4vnbXmAIQLJjBNJ5IdezQDqrZZjDc7hKvTQJOgNZR5xDAvaW3sew== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1741260731; a=rsa-sha256; cv=none; b=niqsSthaEtWp3UaoVl+coq+eJoyr6w+x0iJoMlpz8XfJunTs6T6TKZZ+N41FfmyaUj+ykJ Djebtb9PckPwuESJC5gFNgmoEW2okU6YPz2YPRHn199Skx711gLZvoguatWp7/OodZQvtV /ljbT0WGsuljkgslq+1805GSx7izbdpsuC53V0q5l/SLz0q6/JRGscFrU7dLSboBb2f7Ev x8Me8nqhPDPwf9FP3/1XgrbwZxvneUMEp3PTXApI4WN4oBSjZCVW0BNim4NF1mJjNN/fXw q27j++BHYWeO07grLtllYUvzkYE9wU2ol/A/YSn2esEb7b0ewuHWiUw/5mKAjg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1741260731; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=sArnxEZ3utMyaYzKvo18hubCF9ygEcfBZBWhTgosCxA=; b=VqTvRHcHHTA4s/lfLi57yocBXEsjitoIbqsYnD+z1SLBlGMcHD0902AkWP3aVHpHY//Zl+ 2hXuip7JuW569kyiQl6PXCJ+L0IzPutNrv0o1zP1Tva1nPL80EkC7udSrP0yafAAZJnNbP 8cixhZatwRxV5DMZSn2L/9g1WQp5/WIWjprhEYq1EinFnmfVRSzdyjajdc3Uvi9RNClGDB yodHLmBMGv8LA8txtBfAD/zP3+mTIjuLdpk0H6FxKqgDpSGgBpAwSKWC4roPCG9OBOMTnX n+gnJUrcrtuSMriEWw8nKpV7UBlvgpiGActxHTvvotnJYgq8UZwSoVcF4WMqnA== Received: from smtpclient.apple (ns1.oxydns.net [45.32.91.63]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: zlei/mail) by smtp.freebsd.org (Postfix) with ESMTPSA id 4Z7nMF4WdKztwm; Thu, 06 Mar 2025 11:32:09 +0000 (UTC) (envelope-from zlei@FreeBSD.org) From: Zhenlei Huang Message-Id: Content-Type: multipart/alternative; boundary="Apple-Mail=_35C7DAD6-2678-417F-87A5-DCFFE513A6FC" 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: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.10\)) Subject: Re: git: 234683726708 - main - devclass: make devclass_alloc_unit use M_NOWAIT Date: Thu, 6 Mar 2025 19:32:02 +0800 In-Reply-To: <202503061103.526B32Id022652@gitrepo.freebsd.org> Cc: "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , Warner Losh , "dev-commits-src-main@freebsd.org" To: Mateusz Guzik References: <202503061103.526B32Id022652@gitrepo.freebsd.org> X-Mailer: Apple Mail (2.3696.120.41.1.10) --Apple-Mail=_35C7DAD6-2678-417F-87A5-DCFFE513A6FC Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On Mar 6, 2025, at 7:03 PM, Mateusz Guzik wrote: >=20 > The branch main has been updated by mjg: >=20 > URL: = https://cgit.FreeBSD.org/src/commit/?id=3D234683726708cf5212d672d676d30056= d4133859 >=20 > commit 234683726708cf5212d672d676d30056d4133859 > Author: Mateusz Guzik > AuthorDate: 2025-03-06 11:01:49 +0000 > Commit: Mateusz Guzik > 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); 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. Rather than reverting this, the caller devclass_add_device() should use = M_WAITOK. ``` - 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); ``` Best regards, Zhenlei > + 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=_35C7DAD6-2678-417F-87A5-DCFFE513A6FC Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii

On Mar 6, 2025, at 7:03 PM, Mateusz Guzik <mjg@FreeBSD.org> = wrote:

The branch main has been updated by mjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=3D234683726708cf5212d67= 2d676d30056d4133859

commit = 234683726708cf5212d672d676d30056d4133859
Author: =     Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2025-03-06 11:01:49 +0000
Commit: =     Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2025-03-06 11:01:49 +0000

   devclass: make devclass_alloc_unit use = M_NOWAIT

   The only caller = already does this.

   The = routine can be called with a mutex held making M_WAITOK illegal.

   Sponsored by: =   Rubicon Communications, LLC ("Netgate")
---
sys/kern/subr_bus.c | 8 ++++++--
1 file = changed, 6 insertions(+), 2 deletions(-)

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;

@@ -1264,8 +1265,11 @@ = devclass_alloc_unit(devclass_t dc, device_t dev, int *unitp)
= = int newsize;

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);

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.

Rather than reverting = this, the caller devclass_add_device() should use M_WAITOK.

```
-       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);
```

Best regards,
Zhenlei

+ = = 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=_35C7DAD6-2678-417F-87A5-DCFFE513A6FC--