From nobody Thu Mar 06 11:34:41 2025 X-Original-To: dev-commits-src-all@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 4Z7nQN2V08z5pS7V; Thu, 06 Mar 2025 11:34:52 +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 4Z7nQN2FYtz3sNW; Thu, 06 Mar 2025 11:34:52 +0000 (UTC) (envelope-from zlei@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1741260892; 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=g7w/giCe9B7hMHxWnDTVGUopc6q7+bXaDsTkPdbt430=; b=xYivmioAxR28DYLUPpm/TXk193PUKHA3D3/18SOnzxrUQaFrbHCKDkMKcNES1h3zLCQuzk ZpnsAJUT3u6f79z7fx5Ry6LKI9ByJq8JHQ4WpfbFvh/ZQtDUy29F5QkzyF81iCMvtUIRAs poVvTQlgXD4E0hNDtjZ3YiGS1hcEoyV7+Msn47Rkl1qPuK0nWk7t28/DALAAozs7Pkan/g FTNiRyvnuD65LCci2saagI18cMXGAU3Sk6Jy0+XvDpGcul5YATbO428A/QZCl0hvcmOMK0 8xgmsjv40r3XKAYfxLigzNOXbGlXXsklPaUMdzUiRiOJGrqP5aOPk4TtIuK0XQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1741260892; a=rsa-sha256; cv=none; b=whOgdslRQZzJAuZqvH0ZGUiW9Jqw8OrpeiA64+BHoRjTsmnXULHNoII71LuQVQURZL3P9J hFMqr2e7D/IXToSRLKIw11MQMuRkmQIHpVLz/j6KGdm6yrr7CEDEZRrl7YAmyWX+3dwpgf D8bSgUHwBUSCd/xGEAPtJrRcquqdPg9o2d4I9Lhj1OuDAzeN5pU2dla0VKPMt8oeIiVQ1O CjqKdeFero1x/yTV7VaPrzPFjFA9+FdxkbT1hUfpG7mvyRR8UoD9tSVYyK30EnT/4dI0c5 k8pPuWe7UKcevAnvRcIZ36qQlu6FqiC5exYsPKN7zXKZxPYs5hmGrcPsSoADMw== 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=1741260892; 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=g7w/giCe9B7hMHxWnDTVGUopc6q7+bXaDsTkPdbt430=; b=M6jaQH5wP9v8PNiAOycRy2PFvG9eMuMb1AM0JvTwc+g5IihDi6UrbAeRSjB21RMy5NCH+r /eKwY1eK5ivL+XxWhtTNh6eYLtkU04Zdha+3JNeGRA1ZDiYcjS14OUTCi4jwUVN+1GY1zx zqBJCj+qYh9YHwrFmrQ/Ob3aDrLBpTJHi6WPcPX6SnBev2kEFKXkPGjdXXV/qQmFDvgVCp o9i9liYXCpDopNg0TRB7JKg2NEUKgoSTqM7dv+jpYg1L4X5YMkER4qI+iMIsIZvAzcv2dO yrQxPBYlEuV4s33JgABy2crLOerTx7/5Nbl1cUK7adsufqjk+tBFq7/UlA2OfQ== Received: from smtpclient.apple (unknown [IPv6:2001:19f0:6001:9db:98f0:9fe0:3545:10]) (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 4Z7nQL29LvzsbF; Thu, 06 Mar 2025 11:34:50 +0000 (UTC) (envelope-from zlei@FreeBSD.org) From: Zhenlei Huang Message-Id: <6BE51FFD-DE19-42E6-B115-354BB74B4D78@FreeBSD.org> Content-Type: multipart/alternative; boundary="Apple-Mail=_21A3F846-4569-4526-B2CD-C22C6384E294" List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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:34:41 +0800 In-Reply-To: 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=_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 wrote: >=20 >=20 >=20 >> 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); >=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

On Mar 6, 2025, at 7:32 PM, Zhenlei Huang <zlei@FreeBSD.org> = wrote:



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

Emm, sorry for the noise. I missed the commit = message,
> The routine can be called with a mutex held = making M_WAITOK illegal.


Best regards,
Zhenlei

+ if = (devices =3D=3D NULL)
+ return (ENOMEM);
+ = = dc->devices =3D devices;
= memset(dc->devices + dc->maxunit, 0,
    sizeof(devi= ce_t) * (newsize - dc->maxunit));
= dc->maxunit =3D = newsize;



= --Apple-Mail=_21A3F846-4569-4526-B2CD-C22C6384E294--