From nobody Thu Nov 16 20:54:44 2023 X-Original-To: dev-commits-src-branches@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 4SWXN42J9Tz5155Z; Thu, 16 Nov 2023 20:54:44 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SWXN41nPLz4H9y; Thu, 16 Nov 2023 20:54:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700168084; 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=tG1pH6KoOXoWkdR953iLeq07q80BbUKEx7bUc11pHls=; b=BnZEcfwf/iL+TvrLdhhmVPCJ3SvpPryfxRgk58gGW1v8wdopxi1gZwGAACHs3Vcz5zIy3s bOiROSm0Tugi4sh1F3/yxNRV8/wPqAtqINgdqZGNwxQwd2SJ2WRI2R05eaAyLruDIl8eoS 0NxGgT9ppOIVVgxZ5adFedlL0PCsQQNmtXCFmpKvNo+x6lWk7q3dmI0V9HellyCj878mlv +4rgF+KcH5RdpR/AhDT8VCXx21zu/Kin9ad6Igh7pDigpGL9uPZdlx5D0gI6PGq1fEGrav W2qvDQMdozyHIR/tl1kTG2mTRcodbcGCLI66fMCEGNltgl/ZmnQ3KnxsdfVqtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700168084; 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=tG1pH6KoOXoWkdR953iLeq07q80BbUKEx7bUc11pHls=; b=NNRRY1NLhk/3wmoL6jsUnZSrCdWX0awaniTvZSiRBLo/vitNrVhFcQHJgbPYo1of0WAPMi ckrbRXM4jUH1tExL+UCWhNb9et2xSIGahYl+OWxUB1ayO6TV3V+U/zJXFU+S8jGzp9dBAT vfNP3hUG9rJjJIkNyMI/qEFeVettcWiDZt6ioZpUaGzhrc26RDyba3K2fLOgap5ng7VP3z +4nKgfaqeALtlHq16Va5te800qfAUcKTI5Hk2+06JFC3M3K5XOjUzX0X4WM0whbj/71pks KLnl+J+spCEMxDpSqh6aFENKPwDLHi317iDH9h7etqCouAXVHYGUKX14eRZUaA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1700168084; a=rsa-sha256; cv=none; b=GShrYENYPqzbTJGMT1cu+cV7bSdbOLJzNr4aySTIrt1qnxdVqIT0+BDcRAnn5gyuFjcrTc u3SZXfaoS6OJ0dttdoo31HkBfTvwcZEykVLkUWvNyKKIMcZXYQSsw+GjeCPfz+0as2FFeb nNkRhD6QGbHzIWxvmsUPwBNPBUcRRMRISSj6LSBpPBLmUF40+ZdkRlohVQsZ38hi5fiIui 2xNtku8sIfK3sWfFTbwInPMAysM11nRpVMoulvV18I0n0S9av8awJ3Gj7oMqCM7XaW1aaT MgHdlXvu+bd/55Zp4pyKmsNeWKx7pk9lTXW61gpngak0eWeO2Rd56HlzufKLbg== 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 4SWXN40tpVz1Wr; Thu, 16 Nov 2023 20:54:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3AGKsijv053846; Thu, 16 Nov 2023 20:54:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3AGKsijf053843; Thu, 16 Nov 2023 20:54:44 GMT (envelope-from git) Date: Thu, 16 Nov 2023 20:54:44 GMT Message-Id: <202311162054.3AGKsijf053843@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 7deedba4e586 - stable/14 - uma: New check_align_mask(): Validate alignments (INVARIANTS) List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 7deedba4e58686ad870767bb29c45235c255937a Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=7deedba4e58686ad870767bb29c45235c255937a commit 7deedba4e58686ad870767bb29c45235c255937a Author: Olivier Certner AuthorDate: 2023-10-13 14:09:51 +0000 Commit: Mark Johnston CommitDate: 2023-11-16 15:07:17 +0000 uma: New check_align_mask(): Validate alignments (INVARIANTS) New function check_align_mask() asserts (under INVARIANTS) that the mask fits in a (signed) integer (see the comment) and that the corresponding alignment is a power of two. Use check_align_mask() in uma_set_align_mask() and also in uma_zcreate() to replace the KASSERT() there (that was checking only for a power of 2). Reviewed by: kib, markj MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D42263 (cherry picked from commit 87090f5e5a7b927a2ab30878435f6dcba0705a1d) --- sys/vm/uma_core.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/sys/vm/uma_core.c b/sys/vm/uma_core.c index a27dba4b01f1..661c98b272da 100644 --- a/sys/vm/uma_core.c +++ b/sys/vm/uma_core.c @@ -3249,19 +3249,31 @@ uma_kcreate(uma_zone_t zone, size_t size, uma_init uminit, uma_fini fini, return (zone_alloc_item(kegs, &args, UMA_ANYDOMAIN, M_WAITOK)); } -/* Public functions */ -/* See uma.h */ -void -uma_set_cache_align_mask(unsigned int mask) + +static void +check_align_mask(unsigned int mask) { + KASSERT(powerof2(mask + 1), + ("UMA: %s: Not the mask of a power of 2 (%#x)", __func__, mask)); /* * Make sure the stored align mask doesn't have its highest bit set, * which would cause implementation-defined behavior when passing it as * the 'align' argument of uma_zcreate(). Such very large alignments do * not make sense anyway. */ - uma_cache_align_mask = mask & ~(1U << 31); + KASSERT(mask <= INT_MAX, + ("UMA: %s: Mask too big (%#x)", __func__, mask)); +} + +/* Public functions */ +/* See uma.h */ +void +uma_set_cache_align_mask(unsigned int mask) +{ + + check_align_mask(mask); + uma_cache_align_mask = mask; } /* Returns the alignment mask to use to request cache alignment. */ @@ -3280,8 +3292,7 @@ uma_zcreate(const char *name, size_t size, uma_ctor ctor, uma_dtor dtor, struct uma_zctor_args args; uma_zone_t res; - KASSERT(powerof2(align + 1), ("invalid zone alignment %d for \"%s\"", - align, name)); + check_align_mask(align); /* This stuff is essential for the zone ctor */ memset(&args, 0, sizeof(args));