From nobody Thu Oct 31 00:41:39 2024 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 4Xf4tr05lwz5Zd1j; Thu, 31 Oct 2024 00:41:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Xf4tq6l0Xz4Zv0; Thu, 31 Oct 2024 00:41:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730335299; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=I7kYkb74VxoQll2dXoROfqqgO5nN4OTFza9mhYivvwo=; b=nGxcHFYlBYLWXPY5tw7ueDuMaZxey3PToHvjIz0TcWtQ0ZsG9T1etONLjsq4UfEiyQx01K PNRxYJXKxZhIQyaCdNCv/Y4XD01CpHoig0+5pE+BdYFlnkDHGetwy9EXQUit8jR3heWz1n SZe60dEY3seVAapjX8Tjk1Y1F+R6SoDGwux/37t4uxWCK3QZjuIKsYF0ELQRWdOrfdYlEM WoSnB/sjv08hZXVfNJn60+fQiv3QWHlPllR/rQ1C6WhoJl6aBaOnnIZ7tR5wNOR+9P/re1 SYHbUn72+PaphYM67N4QtFJyaAdx5Alvio5/DRLuisozSqs3xVTsZgC9a2o/vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730335299; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=I7kYkb74VxoQll2dXoROfqqgO5nN4OTFza9mhYivvwo=; b=YKTbHWCVISl7LAQkeSekF9/sx9IPnroIETEMnv2cry7oVSXWscdkCNgoDe0NGR51SE75gS N5kaPD9Gm32h6FB4iVlVy0SX015Z5FHy+++9AfekOtW5VwLwFIobHOIe2mNS8Z06Q12JK+ Xp+4TzHI4yyLEsvPrJSHJ+676QUcplY+kzEmTvYncyD1zOl6+Mqo7MKh7I/iQCtZnesRbR pkHNHzufZ4PXWrs4fQXWDpIcS8pU/jw7F/+5FyBmhxC9rW5gowlXrDGBKjH5Gig+ceAHiP 48LNj7zx8GcXXplbG/tDmwDoqFIOMYXmqpxyPZl/Lc2oTK+OHUH3HjrZlR8H6Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730335299; a=rsa-sha256; cv=none; b=BPtqsaZENnDVFNcOGuRNaue4CWN0BWLNFfVAS/Z43eaaC4iZ5WIgYo1rqKyDKJxzx3kjf6 fY6Fj5OLFrymmlGPtBCaJcpl+IlSjc4jLdwUOZ2Glw+xVtv86xGB3fhsJK4H0Jmc/wxIVJ vGAh8mIvwiSfnhux/T50MCimXU/N0gPc4StDKhBqSTttvxVPfJYTYBLrckY05/uM54i3+V UiJpRYYObENCeQxXteu/f7xkhpSsdNKpYaexrFvREonJCQS6lOi40K+FdEZRGsTlh/piHU saXAyarhBGujdEFWC4pDu7R0CGb5GrgkEF8Mi3C0OB6OwYLpfNm0R33qTTxiGg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Xf4tq6L5BzFP1; Thu, 31 Oct 2024 00:41:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 49V0fdQY055565; Thu, 31 Oct 2024 00:41:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49V0fdvW055560; Thu, 31 Oct 2024 00:41:39 GMT (envelope-from git) Date: Thu, 31 Oct 2024 00:41:39 GMT Message-Id: <202410310041.49V0fdvW055560@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: d0f9b0bd19bf - main - malloc(9): assert wait flags. 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 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d0f9b0bd19bf5dc4031164fd26c5bbc4bab1cc74 Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=d0f9b0bd19bf5dc4031164fd26c5bbc4bab1cc74 commit d0f9b0bd19bf5dc4031164fd26c5bbc4bab1cc74 Author: Dag-Erling Smørgrav AuthorDate: 2024-10-31 00:19:48 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-10-31 00:19:48 +0000 malloc(9): assert wait flags. The check introduced in d3c11994e1e3 was bogus, combining a non-atomic “once” flag with an equally non-thread-safe ppsratecheck. Rather than fix it, just assert what it attempts to enforce: that the malloc flags must include exactly one of M_WAITOK and M_NOWAIT. Fixes: d3c11994e1e3de7445305abd0d41dce2b8d3e6dc Sponsored by: Klara, Inc. Reviewed by: olce, kevans Differential Revision: https://reviews.freebsd.org/D47309 --- sys/kern/kern_malloc.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c index 9d7e0464e0f7..b1347b15e651 100644 --- a/sys/kern/kern_malloc.c +++ b/sys/kern/kern_malloc.c @@ -524,27 +524,13 @@ static int malloc_dbg(caddr_t *vap, size_t *sizep, struct malloc_type *mtp, int flags) { -#ifdef INVARIANTS - int indx; - KASSERT(mtp->ks_version == M_VERSION, ("malloc: bad malloc type version")); - /* - * Check that exactly one of M_WAITOK or M_NOWAIT is specified. - */ - indx = flags & (M_WAITOK | M_NOWAIT); - if (indx != M_NOWAIT && indx != M_WAITOK) { - static struct timeval lasterr; - static int curerr, once; - if (once == 0 && ppsratecheck(&lasterr, &curerr, 1)) { - printf("Bad malloc flags: %x\n", indx); - kdb_backtrace(); - flags |= M_WAITOK; - once++; - } - } + KASSERT((flags & (M_WAITOK | M_NOWAIT)) != 0, + ("malloc: flags must include either M_WAITOK or M_NOWAIT")); + KASSERT((flags & (M_WAITOK | M_NOWAIT)) != (M_WAITOK | M_NOWAIT), + ("malloc: flags may not include both M_WAITOK and M_NOWAIT")); KASSERT((flags & M_NEVERFREED) == 0, ("malloc: M_NEVERFREED is for internal use only")); -#endif #ifdef MALLOC_MAKE_FAILURES if ((flags & M_NOWAIT) && (malloc_failure_rate != 0)) { atomic_add_int(&malloc_nowait_count, 1);