From nobody Thu Mar 06 14:49:03 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 4Z7skn10Msz5phJj for ; Thu, 06 Mar 2025 14:49:21 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "WR4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Z7skn0TVqz3LwQ for ; Thu, 06 Mar 2025 14:49:21 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-pj1-x1032.google.com with SMTP id 98e67ed59e1d1-2ff6cf448b8so1076748a91.3 for ; Thu, 06 Mar 2025 06:49:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1741272555; x=1741877355; darn=freebsd.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=LuWI13uaCsaDRUtYEhDZZ+HLnYAa35A70M1m9iaaXGg=; b=qBWPTIpmE5zrtTQOivV0+VwXvgb0vLku7KgbTBVNzMYHTma8doUcQwBGCZQhzb0+rQ O7tL8hhhAnwZTyJwLMAO2TsHXNQmHrJMxDLmKfKp2cJ7OkC9aEYcYQY7GkTyl3MdQtT4 h7Al42kJ9fCxLhWDgyUMrT5Ov2khQQDCmzDafdwza2Dxwyy1UvDk5NdytJc3Z4IlD6jo Oa4oYNpiMnc+dnJi+YD9auZyFy46AYjkNmGxsIVXvJ2rG3+1WR9R94yrV5VSmeoT3Z6P dZ/7s5g0Piq9ShfEkScMpPP9E7bVq6OYxjSqCGQTjdeWB5LCLALjy/kbtuSaE4xuEA6d b+Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741272555; x=1741877355; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=LuWI13uaCsaDRUtYEhDZZ+HLnYAa35A70M1m9iaaXGg=; b=jGIbQgcUz7GSSJEZWJYBSkaJP5EFyVvcMm+5oUX66hAZwb6JBwOHR9ZokG77vnUboR /GZSpuUCrjNP33+DW0ncQ3SzGVm9dRy27/cvnc6RSRvsT2iWhr7OcA1iu3kAIynmxrRn txnO/lr4KLVo5f3Zr55KdkSFyMUb5dMyWa+DrmtGhT0DEvq4nZX2tnuGtUWCPjYYjQPR /KBbpzwLekKc5Hf9mGarsAs8lb2zdTScE7lJkQPPVJlznKR3gtTQe0SB5nG96VPzlaBg 2lvzKJ/BPzsgHUSOkgAVTDzc2Fn9/tNQaN6ssxxYZswMmntVhtM95K3EAMUSGoZwokIb bsbA== X-Forwarded-Encrypted: i=1; AJvYcCWPt8nFE0jSdTkFwCqXSU/vz9rWDbDXRSOHUYzBSRPNyeVGjYtK7Ss1B5S8tRq8dMEG7ghTgHqYEMSsySMEkue9aZOe@freebsd.org X-Gm-Message-State: AOJu0YyB4hbIJ5ZP3pG3J3yvJhXTEUAER7YczJWo5sxEuycuNEWhApIt 4y+OIBLFmkET7w9ZWmRZEN9Hr7W55GXja7nUX/YpO3FojjLu+ysZCsaTastsWMyE2v75E3LE83T pToW1kJuYsGG/uHLsgGLZeEq99HFPGHTlD9LYwA== X-Gm-Gg: ASbGncvCtoQ2sMmT8rQdtt4kULcMmRQXVmHCduDvHEjAK2v3x6ar3mFsbttZBBsPVvZ 8L8uDTU9xRdXhDuQZIMMOkwAoMh/R9wSLhnBaIj6K78hGjHy/Jl+sYllrgDYJp8tuLIk0EFzsln fb/3wEdHHedjG8lIKESOJwAskPAXmAs9d9UOovdhg+7A9ru1va/b30t9lg9cBx X-Google-Smtp-Source: AGHT+IH4LS9b/5Ax+Sch5zBblE2YNCyiO9ysgNP6NU/WMgVWG6hHYFY76nnt4/h4ncbUmRV7HjO0rwHEWqI/5tr4fYE= X-Received: by 2002:a17:90b:2402:b0:2ff:53ad:a0ec with SMTP id 98e67ed59e1d1-2ff53ada24fmr7285814a91.21.1741272554702; Thu, 06 Mar 2025 06:49:14 -0800 (PST) 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 References: <202503061103.526B32Id022652@gitrepo.freebsd.org> In-Reply-To: From: Warner Losh Date: Thu, 6 Mar 2025 06:49:03 -0800 X-Gm-Features: AQ5f1Jqwd1nJcfqZUIHjktf1P1pr3ak_iifXoXZxpCxOVrw2-lGJZHup8iu7aig Message-ID: Subject: Re: git: 234683726708 - main - devclass: make devclass_alloc_unit use M_NOWAIT To: Mateusz Guzik Cc: Zhenlei Huang , Mateusz Guzik , src-committers , "" , Warner Losh , "" Content-Type: multipart/alternative; boundary="00000000000014a6a1062fad9ca8" X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US] X-Rspamd-Queue-Id: 4Z7skn0TVqz3LwQ X-Spamd-Bar: ---- --00000000000014a6a1062fad9ca8 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Mar 6, 2025, 3:35=E2=80=AFAM Mateusz Guzik wrot= e: > On Thu, Mar 6, 2025 at 12:32=E2=80=AFPM Zhenlei Huang = wrote: > > > > > > > > On Mar 6, 2025, at 7:03 PM, Mateusz Guzik wrote: > > > > The branch main has been updated by mjg: > > > > URL: > https://cgit.FreeBSD.org/src/commit/?id=3D234683726708cf5212d672d676d3005= 6d4133859 > > > > commit 234683726708cf5212d672d676d30056d4133859 > > Author: Mateusz Guzik > > AuthorDate: 2025-03-06 11:01:49 +0000 > > Commit: Mateusz Guzik > > 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. From 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. > > > > Per my commit message this is callable from a *NOT* sleepable context. > > Here is a splat we got at Netgate: > > uma_zalloc_debug: zone "malloc-16" with the following non-sleepable locks > held: > exclusive sleep mutex SD slot mtx (sdhci) r =3D 0 (0xd8dec028) locked @ > > /var/jenkins/workspace/pfSense-Plus-snapshots-25_03-main/sources/FreeBSD-= src-plus-RELENG_25_03/sys/dev/sdhci/sdhci.c:688 > stack backtrace: > #0 0xc0330ebc at witness_debugger+0x78 > #1 0xc033217c at witness_warn+0x428 > #2 0xc05b0a58 at uma_zalloc_debug+0x34 > #3 0xc05b067c at uma_zalloc_arg+0x30 > #4 0xc0291760 at malloc+0x8c > #5 0xc02920ec at reallocf+0x14 > #6 0xc02f8894 at devclass_add_device+0x1e8 > #7 0xc02f6c78 at make_device+0xe0 > #8 0xc02f6abc at device_add_child_ordered+0x30 > #9 0xc0156e0c at sdhci_card_task+0x238 > #10 0xc0324090 at taskqueue_run_locked+0x1b4 > #11 0xc0323ea0 at taskqueue_run+0x50 > #12 0xc0275f88 at ithread_loop+0x264 > #13 0xc0271f28 at fork_exit+0xa0 > #14 0xc05f82d4 at swi_exit+0 > > It may be some callers are sleepable. Perhaps a different variant > accepting flags would be prudent, but I have no interest in looking > into that. > This is a big in sdhci_card_task. Newbus in general isn't callable from a sleepable context. Warner > ``` > > - 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; > > > > > > > > > > > -- > Mateusz Guzik > --00000000000014a6a1062fad9ca8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Thu, Mar 6, 2025, 3:35=E2=80= =AFAM Mateusz Guzik <mjguzik@gmail.= com> wrote:
On Thu, Mar 6, 2= 025 at 12:32=E2=80=AFPM Zhenlei Huang <zlei@freebsd.org> wrote:
>
>
>
> On Mar 6, 2025, at 7:03 PM, Mateusz Guzik <mjg@FreeBSD.org> wrot= e:
>
> The branch main has been updated by mjg:
>
> URL: https://cgit.FreeBSD.org/src/commit/?id=3D234683726708cf5212d672d676d300= 56d4133859
>
> commit 234683726708cf5212d672d676d30056d4133859
> Author:=C2=A0 =C2=A0 =C2=A0Mateusz Guzik <mjg@FreeBSD.org>
> AuthorDate: 2025-03-06 11:01:49 +0000
> Commit:=C2=A0 =C2=A0 =C2=A0Mateusz Guzik <mjg@FreeBSD.org>
> CommitDate: 2025-03-06 11:01:49 +0000
>
>=C2=A0 =C2=A0 devclass: make devclass_alloc_unit use M_NOWAIT
>
>=C2=A0 =C2=A0 The only caller already does this.
>
>=C2=A0 =C2=A0 The routine can be called with a mutex held making M_WAIT= OK illegal.
>
>=C2=A0 =C2=A0 Sponsored by:=C2=A0 =C2=A0Rubicon Communications, LLC (&q= uot;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,
> -=C2=A0 =C2=A0 newsize * sizeof(*dc->devices), M_BUS, M_WAITOK); > + devices =3D reallocf(dc->devices,
> +=C2=A0 =C2=A0 newsize * sizeof(*dc->devices), M_BUS, M_NOWAIT); >
>
> I'd recommend against this. From the commit message of f3d3c63442f= f, Warner said,
> > In addition, transition to M_WAITOK since this is a sleepable con= text
> So, the M_WAITOK is intentional.
>
> Rather than reverting this, the caller devclass_add_device() should us= e M_WAITOK.
>

Per my commit message this is callable from a *NOT* sleepable context.

Here is a splat we got at Netgate:

uma_zalloc_debug: zone "malloc-16" with the following non-sleepab= le locks held:
exclusive sleep mutex SD slot mtx (sdhci) r =3D 0 (0xd8dec028) locked @
/var/jenkins/workspace/pfSense-Plus-snapshots-25_03-main/sources/FreeBSD-sr= c-plus-RELENG_25_03/sys/dev/sdhci/sdhci.c:688
stack backtrace:
#0 0xc0330ebc at witness_debugger+0x78
#1 0xc033217c at witness_warn+0x428
#2 0xc05b0a58 at uma_zalloc_debug+0x34
#3 0xc05b067c at uma_zalloc_arg+0x30
#4 0xc0291760 at malloc+0x8c
#5 0xc02920ec at reallocf+0x14
#6 0xc02f8894 at devclass_add_device+0x1e8
#7 0xc02f6c78 at make_device+0xe0
#8 0xc02f6abc at device_add_child_ordered+0x30
#9 0xc0156e0c at sdhci_card_task+0x238
#10 0xc0324090 at taskqueue_run_locked+0x1b4
#11 0xc0323ea0 at taskqueue_run+0x50
#12 0xc0275f88 at ithread_loop+0x264
#13 0xc0271f28 at fork_exit+0xa0
#14 0xc05f82d4 at swi_exit+0

It may be some callers are sleepable. Perhaps a different variant
accepting flags would be prudent, but I have no interest in looking
into that.

This is a big in sdhci_card_task. Newbus in general isn't cal= lable from a sleepable context.


Warner

> ```
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0dev->nameunit =3D malloc(buflen, M_BUS,= M_NOWAIT|M_ZERO);
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0if (!dev->nameunit)
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return (ENOMEM= );
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0dev->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,
>=C2=A0 =C2=A0 sizeof(device_t) * (newsize - dc->maxunit));
> dc->maxunit =3D newsize;
>
>
>
>


--
Mateusz Guzik <mjguzik gmail.com>
--00000000000014a6a1062fad9ca8--