From nobody Thu Dec 21 13:43:58 2023 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 4Sws8v19zmz54q3B; Thu, 21 Dec 2023 13:43:59 +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 4Sws8t6mrBz4PCj; Thu, 21 Dec 2023 13:43:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703166239; 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=t5JQCip4qhCU3IV5YYU5shfsMaKnDnrHoiETbDctVPI=; b=ICsF7AJbH1c26bDuoldSSnUDilH+Fee2dC/05/xtA1gDhE6doN860HR3Gl9NQkdgYNx1Kd iY3tZQ1wGpSn+JHprOZbiGFUW0OivqvRa6rDt+vQQ35qdf9k4Cv22W9GgiLrdB+JuCirc0 DRSvgFHyIGTfrb6UffGAy6tdnQZ+op5t+llpaI/M5n9JhCxSxXACA/kGHY75HleDI82DFF UhrNlOoiLxuPj4cAuf0sr/cTV0ef29ufsH5BdTQdWUqHDuqW8R1uNgzNEzK+obpMYLdIQD QvmzKYOsEdJVCcBrG1/prH8CjYJpwHfXW1cKjT3o/cvtPwsA1LXE/3/AR6CwYA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1703166238; a=rsa-sha256; cv=none; b=gd0OAd+69Ch0WAsISQwaEc7bw4XFnJI5MemoMzhS5Gt7oiWnOKm94rhwHhCag9WryW1duU dA3qna6GFZVm5p2zKKN24efh3SxiQ6VthmGb8OMEwF7zsa5disjZ7jrXd/3kNZL90sYfXx XaGzua0mB7pkWRxSGzNALbg00EF3emC+1yu4Ey/MZaYorsTcl3+u6aKF1zdS/KiUQ7pOp5 pp1RVVLwggnCQZWu0MfQUQxqqmLeqsPCsNmXcxhkqUYSW22FVsb/nBqHT4lCh7M2HOKsI0 t3qXBEegYVoMacfbATdjoQDnh5X1RXOSfKgnYoiPXt3gW+a8E00PTr63vuF4/Q== 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=1703166238; 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=t5JQCip4qhCU3IV5YYU5shfsMaKnDnrHoiETbDctVPI=; b=Jfat1YIi4E77qhyLauKCqPfLoxrtE1q1/gyHGv3wacs5CeHlr8kpJCxw61GqCXKcmOSYKP paphqLNEcOBG+oCVH0GO6TvGFxq8PxtXyegA4TCdcIV8Pukbd4GkAprhP0RoAfOD/NWGKb ZYnvUAgGOusynfNunTXwvAFEuCP+DQY9Ov0VfEFgTKi98K7qKpqYEGm7PnepVl5ecX5vR0 9BHU3ydBkKBYBt3zhV9t1DGQSMlKrjmjD0aY+rsJ8fwhiaGHt2C8Tl6sgKLLa2DIDGfsGw bt1+vBg4BYze8he8u7u08uXnjFPvceiPi4yuXF2A3jP5uqEUwowYN8IGLB8DDQ== 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 4Sws8t5tHfzZv0; Thu, 21 Dec 2023 13:43:58 +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 3BLDhwOw080055; Thu, 21 Dec 2023 13:43:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BLDhwYu080052; Thu, 21 Dec 2023 13:43:58 GMT (envelope-from git) Date: Thu, 21 Dec 2023 13:43:58 GMT Message-Id: <202312211343.3BLDhwYu080052@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Olivier Certner Subject: git: 27199e55a4d5 - stable/13 - uma: New check_align_mask(): Validate alignments (INVARIANTS) 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: olce X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 27199e55a4d568659d3a4b9985e736e8e5ee3dfe Auto-Submitted: auto-generated The branch stable/13 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=27199e55a4d568659d3a4b9985e736e8e5ee3dfe commit 27199e55a4d568659d3a4b9985e736e8e5ee3dfe Author: Olivier Certner AuthorDate: 2023-10-13 14:09:51 +0000 Commit: Olivier Certner CommitDate: 2023-12-21 13:40:09 +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 Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D42263 (cherry picked from commit 87090f5e5a7b927a2ab30878435f6dcba0705a1d) Approved by: markj (mentor) --- 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 0f3d2591c893..2236df90dfc0 100644 --- a/sys/vm/uma_core.c +++ b/sys/vm/uma_core.c @@ -3188,19 +3188,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. */ @@ -3219,8 +3231,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));