From nobody Sun Aug 11 00:30:05 2024 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 4WhJSw5pV5z5TT9n for ; Sun, 11 Aug 2024 00:30:08 +0000 (UTC) (envelope-from shawn.webb@hardenedbsd.org) Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) (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 4WhJSv3V6hz4Mpk for ; Sun, 11 Aug 2024 00:30:07 +0000 (UTC) (envelope-from shawn.webb@hardenedbsd.org) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=hardenedbsd.org header.s=google header.b=h4Tcu8AF; dmarc=none; spf=pass (mx1.freebsd.org: domain of shawn.webb@hardenedbsd.org designates 2607:f8b0:4864:20::d2c as permitted sender) smtp.mailfrom=shawn.webb@hardenedbsd.org Received: by mail-io1-xd2c.google.com with SMTP id ca18e2360f4ac-81fb419f77bso146292039f.2 for ; Sat, 10 Aug 2024 17:30:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hardenedbsd.org; s=google; t=1723336206; x=1723941006; darn=freebsd.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Q8lto1sxnR8QAL4cOV0kjCkHA/oS8HBucLnxSHrmTEI=; b=h4Tcu8AFtAT48OfcqIipdKjFeeYy7SsaO23nu858iufi2H6uF6GKvkveDtxp11J+L2 ThQf851tuhE2+1oorLW0FY5OG+MUfMRektLEsQ8T+5JKWZxl62jS7lgCfQAGq47wXKZX mYpSGxu0nG3deOsKGrcsXYxHgZ35Rn5a/Uppz3gk90jmkeWF/SZmMK0K2CfFPtb7zNGe u4qsmzfYYvIh9F4m3GGxgGMfU4AKbteWiu+85W2oOizDbhRF9ZX5NBzGDld5hc9IgA0t iux6ulmOi7fZuMFckmPXUbhBrUYDLN9iwxK0GesAvrIyg2h2JcVictNTsjpHYo7WWLLG l6YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723336206; x=1723941006; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Q8lto1sxnR8QAL4cOV0kjCkHA/oS8HBucLnxSHrmTEI=; b=kTw2kCA6IF2rDDyOG0zynT7+18q71RSQPtX5htahPgc18ZtpCEVamryN1tR7nBi0jV 3nEXsRjB8HWESPFsi24K/4txasUW2CvBCM+/fBuIcMwxR+NrsXcreoRY8Rh3vT45C4n/ 0vhd5ZiIGs4YnznQUts23x43x1xR2+yZT56TtGfM08nUtmuyDUmFOriCHLYAPQrCI4BP r+LX//n+JOLjqdgeZzDeyujJ7MGVo7tRrllgCxW8EcgribQMQhtcyIS2bq2mUXbVZKcU tZwO7qqzJu/n9f4XBk9XQ532IdU2TWC2gj+k5ma44SvO1cfK4zHRr3GeMfUkW2KgFwXt xxIQ== X-Forwarded-Encrypted: i=1; AJvYcCW9yi9W7yIfUQrNhdcrJX+k5ys8BftFaZUIvtQTvHtAUGCqD3A91LGADkbNsiBF/fdbW7G7f34uFtpdNRfJnauyXjqz2QY6lKY7PgHDhVDO X-Gm-Message-State: AOJu0YzbhI2Hod8xRYoF3BmlSRYoEj3VWWjt90lfL6WXkVbO6vQ9nOaT gcwb/syiESQZPhDaxP7Z9jLKLp0/6PPHldfBiDPLL943kYj1wQ6qe9WebatuIlY= X-Google-Smtp-Source: AGHT+IHZacMCH62j90WpYfqrgvyOTHTEQ4UAqQy/myOuwnqihTS6PDtAgwMfcwmQatqiOB/5zbgcFA== X-Received: by 2002:a05:6602:1541:b0:81f:a288:efa7 with SMTP id ca18e2360f4ac-8225eedfb24mr720872839f.15.1723336206263; Sat, 10 Aug 2024 17:30:06 -0700 (PDT) Received: from mutt-hbsd (174-24-73-190.clsp.qwest.net. [174.24.73.190]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4ca76a01356sm786189173.88.2024.08.10.17.30.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Aug 2024 17:30:05 -0700 (PDT) Date: Sun, 11 Aug 2024 00:30:05 +0000 From: Shawn Webb To: "Bjoern A. Zeeb" Cc: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: 4fab5f005482 - main - kern_malloc: fold free and zfree together into one __always_inline func Message-ID: X-Operating-System: FreeBSD mutt-hbsd 15.0-CURRENT-HBSD FreeBSD 15.0-CURRENT-HBSD X-PGP-Key: https://git.hardenedbsd.org/hardenedbsd/pubkeys/-/blob/master/Shawn_Webb/03A4CBEBB82EA5A67D9F3853FF2E67A277F8E1FA.pub.asc References: <202407261048.46QAmNLD085636@gitrepo.freebsd.org> 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 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="mhrpzhpejy63fjop" Content-Disposition: inline In-Reply-To: <202407261048.46QAmNLD085636@gitrepo.freebsd.org> X-Spamd-Bar: ----- X-Spamd-Result: default: False [-5.10 / 15.00]; SIGNED_PGP(-2.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-0.998]; MID_RHS_NOT_FQDN(0.50)[]; R_DKIM_ALLOW(-0.20)[hardenedbsd.org:s=google]; MIME_GOOD(-0.20)[multipart/signed,text/plain]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36]; MIME_TRACE(0.00)[0:+,1:+,2:~]; ARC_NA(0.00)[]; MISSING_XM_UA(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::d2c:from]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; DMARC_NA(0.00)[hardenedbsd.org]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_TLS_LAST(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[dev-commits-src-all@freebsd.org]; MLMMJ_DEST(0.00)[dev-commits-src-all@freebsd.org]; DKIM_TRACE(0.00)[hardenedbsd.org:+] X-Rspamd-Queue-Id: 4WhJSv3V6hz4Mpk --mhrpzhpejy63fjop Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hey Bjoern, For some reason this commit breaks booting on two of my Dell laptops. I'm unsure why. Reverting this particular commit makes them happy again. Thanks, --=20 Shawn Webb Cofounder / Security Engineer HardenedBSD Tor-ified Signal: +1 303-901-1600 / shawn_webb_opsec.50 https://git.hardenedbsd.org/hardenedbsd/pubkeys/-/raw/master/Shawn_Webb/03A= 4CBEBB82EA5A67D9F3853FF2E67A277F8E1FA.pub.asc On Fri, Jul 26, 2024 at 10:48:23AM +0000, Bjoern A. Zeeb wrote: > The branch main has been updated by bz: >=20 > URL: https://cgit.FreeBSD.org/src/commit/?id=3D4fab5f005482aa88bc0f7d7a0a= 5e81b436869112 >=20 > commit 4fab5f005482aa88bc0f7d7a0a5e81b436869112 > Author: Bjoern A. Zeeb > AuthorDate: 2024-07-24 15:56:32 +0000 > Commit: Bjoern A. Zeeb > CommitDate: 2024-07-26 10:46:37 +0000 >=20 > kern_malloc: fold free and zfree together into one __always_inline fu= nc > =20 > free() and zfree() are essentially the same copy and pasted code with > the extra explicit_bzero() (and formerly kasan) calls. Add a bool to= add > the extra functionality and make both functions a wrapper around the = common > code and let the compiler do the optimization based on the bool input > when inlining. > =20 > No functional changes intended. > =20 > Suggested by: kib (in D45812) > Sponsored by: The FreeBSD Foundation > MFC after: 10 days > Reviewed by: kib, markj > Differential Revision: https://reviews.freebsd.org/D46101 > --- > sys/kern/kern_malloc.c | 90 +++++++++++++++-----------------------------= ------ > 1 file changed, 27 insertions(+), 63 deletions(-) >=20 > diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c > index 37684e26b451..ebdd00808f22 100644 > --- a/sys/kern/kern_malloc.c > +++ b/sys/kern/kern_malloc.c > @@ -914,15 +914,8 @@ free_dbg(void **addrp, struct malloc_type *mtp) > } > #endif > =20 > -/* > - * free: > - * > - * Free a block of memory allocated by malloc. > - * > - * This routine may not block. > - */ > -void > -free(void *addr, struct malloc_type *mtp) > +static __always_inline void > +_free(void *addr, struct malloc_type *mtp, bool dozero) > { > uma_zone_t zone; > uma_slab_t slab; > @@ -938,8 +931,8 @@ free(void *addr, struct malloc_type *mtp) > =20 > vtozoneslab((vm_offset_t)addr & (~UMA_SLAB_MASK), &zone, &slab); > if (slab =3D=3D NULL) > - panic("free: address %p(%p) has not been allocated", > - addr, (void *)((u_long)addr & (~UMA_SLAB_MASK))); > + panic("%s(%d): address %p(%p) has not been allocated", __func__, > + dozero, addr, (void *)((uintptr_t)addr & (~UMA_SLAB_MASK))); > =20 > switch (GET_SLAB_COOKIE(slab)) { > case __predict_true(SLAB_COOKIE_SLAB_PTR): > @@ -947,79 +940,50 @@ free(void *addr, struct malloc_type *mtp) > #if defined(INVARIANTS) && !defined(KASAN) > free_save_type(addr, mtp, size); > #endif > + if (dozero) > + explicit_bzero(addr, size); > uma_zfree_arg(zone, addr, slab); > break; > case SLAB_COOKIE_MALLOC_LARGE: > size =3D malloc_large_size(slab); > + if (dozero) > + explicit_bzero(addr, size); > free_large(addr, size); > break; > case SLAB_COOKIE_CONTIG_MALLOC: > - size =3D contigmalloc_size(slab); > + size =3D round_page(contigmalloc_size(slab)); > + if (dozero) > + explicit_bzero(addr, size); > kmem_free(addr, size); > - size =3D round_page(size); > break; > default: > - panic("%s: addr %p slab %p with unknown cookie %d", __func__, > - addr, slab, GET_SLAB_COOKIE(slab)); > + panic("%s(%d): addr %p slab %p with unknown cookie %d", > + __func__, dozero, addr, slab, GET_SLAB_COOKIE(slab)); > /* NOTREACHED */ > } > malloc_type_freed(mtp, size); > } > =20 > /* > - * zfree: > - * > - * Zero then free a block of memory allocated by malloc. > - * > + * free: > + * Free a block of memory allocated by malloc/contigmalloc. > * This routine may not block. > */ > void > -zfree(void *addr, struct malloc_type *mtp) > +free(void *addr, struct malloc_type *mtp) > { > - uma_zone_t zone; > - uma_slab_t slab; > - u_long size; > - > -#ifdef MALLOC_DEBUG > - if (free_dbg(&addr, mtp) !=3D 0) > - return; > -#endif > - /* free(NULL, ...) does nothing */ > - if (addr =3D=3D NULL) > - return; > - > - vtozoneslab((vm_offset_t)addr & (~UMA_SLAB_MASK), &zone, &slab); > - if (slab =3D=3D NULL) > - panic("free: address %p(%p) has not been allocated", > - addr, (void *)((u_long)addr & (~UMA_SLAB_MASK))); > + _free(addr, mtp, false); > +} > =20 > - switch (GET_SLAB_COOKIE(slab)) { > - case __predict_true(SLAB_COOKIE_SLAB_PTR): > - size =3D zone->uz_size; > -#if defined(INVARIANTS) && !defined(KASAN) > - free_save_type(addr, mtp, size); > -#endif > - kasan_mark(addr, size, size, 0); > - explicit_bzero(addr, size); > - uma_zfree_arg(zone, addr, slab); > - break; > - case SLAB_COOKIE_MALLOC_LARGE: > - size =3D malloc_large_size(slab); > - kasan_mark(addr, size, size, 0); > - explicit_bzero(addr, size); > - free_large(addr, size); > - break; > - case SLAB_COOKIE_CONTIG_MALLOC: > - size =3D round_page(contigmalloc_size(slab)); > - explicit_bzero(addr, size); > - kmem_free(addr, size); > - break; > - default: > - panic("%s: addr %p slab %p with unknown cookie %d", __func__, > - addr, slab, GET_SLAB_COOKIE(slab)); > - /* NOTREACHED */ > - } > - malloc_type_freed(mtp, size); > +/* > + * zfree: > + * Zero then free a block of memory allocated by malloc/contigmalloc. > + * This routine may not block. > + */ > +void > +zfree(void *addr, struct malloc_type *mtp) > +{ > + _free(addr, mtp, true); > } > =20 > /* >=20 --mhrpzhpejy63fjop Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEA6TL67gupaZ9nzhT/y5nonf44foFAma4BgQACgkQ/y5nonf4 4fopbxAAm/6MB6r3tvgPZPpbWK5Mh77BiDvgza/sdICZUElY+4vwwp2iFV1y2Twn Crp7nAM5Y3Ky0TMd+Uu+Lr2yx3lZPoRL/dogz0N5sWGeRukh/co5qrh8xvwsqJsg q2cA6vUoZt5zvibyuipCr5LDJSgN0ROJj3Ka+ZpuYSmg289ezEQ2hvsmYqqPm79F rNiNeQPDDX8cHR6IulXCWku56jjYN5E3CpVOxaa2oXP/hCe7dZ3jz5bnT0aLzqOp /EgqWNYnsYwJ/q6vyfVcE3+Su7hkBa0gidx0JE18hNeqUPwxPZBuTq+ayj66h3sk Kuybn7zf/9ulhE3dsM2dXUk38ki4cYyTqrnlUmf+TlUnC+cT2Bkz303DF8OO9idW 9PLvatfCcIZBMCTVWbFMqg5WZyr51xRciBp/EleAJ0RiEFQSgj+4MCly+uy3HGIe vtlwNHQ/0FxzhXpyVmuADQGYTBHPCEDrQNugrgX2BOGBRVIEw0o120tmTf6MqplU Bfgk1zSYIJ9bUnI4nrfnhWphNnX8QbyOIQiBeoNPZJXVc9GUt+AstZZIyDHg3iiT 9ejjqjvnRSTwdBcY6MsuTpYLozZe/PYu2Ed83KamcvaYDb1Jw8IwsuIMRn2CuVKv hpfc8JFvSF+a9OM9PlP63hRXAs4DSdqQhsRy74+fwmJrNj6Oi7U= =4y6D -----END PGP SIGNATURE----- --mhrpzhpejy63fjop--