From patchwork Fri Aug 9 07:33:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13758473 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 349D8C52D73 for ; Fri, 9 Aug 2024 07:33:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5550D6B009F; Fri, 9 Aug 2024 03:33:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D3F56B00A0; Fri, 9 Aug 2024 03:33:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 336C96B009F; Fri, 9 Aug 2024 03:33:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id EBC806B009A for ; Fri, 9 Aug 2024 03:33:12 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 989701A0A1B for ; Fri, 9 Aug 2024 07:33:12 +0000 (UTC) X-FDA: 82431891024.08.557D86A Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf03.hostedemail.com (Postfix) with ESMTP id D1A7A20031 for ; Fri, 9 Aug 2024 07:33:10 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=U1GOg7df; spf=pass (imf03.hostedemail.com: domain of kees@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=kees@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723188757; a=rsa-sha256; cv=none; b=xg7I4ebMIANLaShDWXWJqRpe03ywpOepny5OSAHahO2BtYQG5oCfEZapGLvgJZZdYdBURM O0hpFu8hxwvJCt4hYgbMTYQlsug8y3QIxQq0kXL9Qq4L97lXvUcVNSdbObtnZ+I3DFojk3 q6YUgI46CBJg9+Wvgnm3KxmgZ3dcVP0= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=U1GOg7df; spf=pass (imf03.hostedemail.com: domain of kees@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=kees@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723188757; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=r2Pzva1Psfsb7VABsc6WR1oxtK6JxECeObZJPE4S0PM=; b=PRECEt/q0YZcAVw+s0592aVpVT2d74ycHT7vvh3hEAJGJZdUCn5lR1npp4zMkem41G9r8r emmv03u/fLrYmMi7BWzKaO7p8ncs1y6FsvLTx3CKeznyBe3iV2zcyW7oIrNKQ+qa52WyEW 9UY99FGGaDsBK+ukWULKkK0jeqrZ1Cw= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id C8ACE61645; Fri, 9 Aug 2024 07:33:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F687C32782; Fri, 9 Aug 2024 07:33:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723188789; bh=fH+32u2hbe+aYvteHR+ZPHJXyfY1tBWhDA7Vvn2Or58=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U1GOg7dfFb6vCTpdmAesrPycht4b3E2BP61/NHu5KkhADUw+F/qMwpsb+4EE0wwPr L9nvFDqSei8WJyngCv1Q76XygeWaSsjBlLrD6F/LC8/k4VknfL0og/dzm76kmgZgtR 95TPrS8GpHcyJsvMNXhSCnbwb/zN8o2cGRSd7yux2dwYNZdWYITUiYaoPN0QRrAz4J xWzfOO8GT/bjnPzIqghQGJWNHo7TvFmqxfVY9RsL2FSgfXLSt5noN6OfXW0U8mVhWW LIZVWRO8MeNF1Hpm2FoGdrC++nOc8Th3OtGsIxGUZ8FgbOdZ6MVMjlaGpBWyS3Y5Uq lUO1diWANHxyg== From: Kees Cook To: Vlastimil Babka Cc: Kees Cook , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org, Suren Baghdasaryan , Kent Overstreet , "GONG, Ruiqi" , Jann Horn , Matteo Rizzo , jvoisin , Xiu Jianfeng , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH 1/5] slab: Introduce kmem_buckets_destroy() Date: Fri, 9 Aug 2024 00:33:02 -0700 Message-Id: <20240809073309.2134488-1-kees@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240809072532.work.266-kees@kernel.org> References: <20240809072532.work.266-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2139; i=kees@kernel.org; h=from:subject; bh=fH+32u2hbe+aYvteHR+ZPHJXyfY1tBWhDA7Vvn2Or58=; b=owGbwMvMwCVmps19z/KJym7G02pJDGlbjxkoHv8l8yD/Mrump/fE6Mr5/aFh0Z63wl+F6swJe 9mx9VNSRykLgxgXg6yYIkuQnXuci8fb9nD3uYowc1iZQIYwcHEKwER0XzEyzOnisNb8799w6KzH TqX4LWYLH5sfsG/JsPy17/be9sMdXxgZDioISWWoefx3MnrGUf7s0jzWyOPSmyWaxZQnrvt/sGs bNwA= X-Developer-Key: i=kees@kernel.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Stat-Signature: 77ipjejseuzssgrmr3gp5s4abozg7qaf X-Rspamd-Queue-Id: D1A7A20031 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1723188790-378772 X-HE-Meta: U2FsdGVkX1/WWXCrmKMPaPGh84IlBnTIGQIrlnf7QmNzEuUDXeEfZjdqx0FiHe3CKA1SSxWfpuUI3R2Z1AcVjDNwGcuYd/fc5DkJ4+cdqgnrcAsqSU9GTd33Ut+P+W7/4I7OGIkerFt2TOZTRssolRr0sDi0EMOqpnXbnJYuWALkDI0Pz8DE2wWlmeGxm/R/d4NREuxd3aVlFJA0gXXXGL351x60oiVa4Wu+ZljEnsKwSqXoMcOMaOu3KRBA/rqvpwFYj7K18S78KQpQI78jnkBV6k0WKJk4uo8pcRR4dZqowcQxO36F9nXzl67cQmovDdlnzjPHGKqwUXhYy8WHDoB5nXFmkqGhunijBq7uvKU1NM0EDVHEoFGUbobGTjXFZYg36veRaypwMZZCVc5IUFNcCgOe7y5EnmjkIWvkCYY/JL6R1F6by0RMpo5DljuqQ6lcjxPKazQ423qjDcwFqhmMwujfNfTEBVf78+8f1jLrQF8pQ78lkInxeai2FlO2sUyK03K4//T+wo7jTRosU1UV8nN07HnifR9s3BdW4KDzW54iSwtylk+C/Qet7ydkkOLyt5ItVYW199A/HYKUJkPAPyYsRkVXzOw5wAUid1vpbHOCe3fQ9/WL/gsI69GOhaPa+CcEE9hTHoGL8y+SCYj0bvP5rHdB7ANYg1OMuG3mZ/SOPRGrmhbUNVD0S5i8S0mUs3sc/ECaSzI/faMfCLS1mIuPSd+d2+GLKCdbEGGJu6fKoRz9flnhWpR/FkJ8rGZWnQewdxzX1YIyvsFzl9IN1HPD+EVxhFBv2qwLK9L3nSw+C3F++YzcVi3lBZMTyInxplkee2SctLJYNvbw2ABQh+Vk220I3YNzbbcqYsyBu5i+G+plPcviILXbQjLEZz7bzIruA4+rv6oCAjzk6QTOhxqqKfq3L3IQTRqGEoANZUM5jRHardbfVYAzX29HZSxyTgnGArcJ+cYwyZD Jts5Th5k EuNgrXKCn7kQV1qot/OdEHFoFFbvAcQlRcULdmZpDXhNS0e9dfQ09TLJnj6nFLGnmGNAhvxG3XvttexYPrfsoql4WRcNrXSJ/7NKrIzXU0imBEYJY9DcXZlc1TzEq8mYov9Yk7P66+U8O3Q1HLXUncOLRMzI2cf74lKlMAhozcnXdJDXnvqhSEpxtuPRCrH0srsmXkRWn8MIbeP+/ajxWKTlcx+okq9YTIPBDquaaa0pLsNANGwFW4+gGViVwj0hoBnop1XYqCr6mlGnkAvOKJ99XK6RlJGM9HUSxfHankkkvVErWJdS1yu8hqXf3CJE9XyJY1kOfBc1qy7HabYAlMM3a0l99fVcGYlcvTPUcHbhP+PvWGli6DLndT/bHx4LCGkL7U/Poe1WXznwP9Ux7/AUog2KlpkreUMDyTh7OAb6Q9+50B+QmZ9gSm261VxFxwOYBDVvN1CGaTjsdudqwYkbBkVAMmjCyzgL2wkYJwhbJ4TU9veV3TijvkwhmXJ/I7Ptw1NXDMdC5GGr/1vj5G6PSbtl4mqpC5rpdzvZpIkCAdsNogSTEJD4lJFB5oKb/0bEnAjRzhwYBfnKIxwA4t4Wx1ZSK7JDkzIWmVe/i/1iZO5qQj3rjLeEd/jsfJGKElQhE X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Modular use of kmem_buckets_create() means that kmem_buckets will need to be removed as well. Introduce kmem_buckets_destroy(), matching kmem_cache_destroy(). Signed-off-by: Kees Cook --- Cc: Vlastimil Babka Cc: Christoph Lameter Cc: Pekka Enberg Cc: David Rientjes Cc: Joonsoo Kim Cc: Andrew Morton Cc: Roman Gushchin Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com> Cc: linux-mm@kvack.org --- include/linux/slab.h | 1 + mm/slab_common.c | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index eb2bf4629157..86cb61a0102c 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -552,6 +552,7 @@ void kmem_cache_free(struct kmem_cache *s, void *objp); kmem_buckets *kmem_buckets_create(const char *name, slab_flags_t flags, unsigned int useroffset, unsigned int usersize, void (*ctor)(void *)); +void kmem_buckets_destroy(kmem_buckets *b); /* * Bulk allocation and freeing operations. These are accelerated in an diff --git a/mm/slab_common.c b/mm/slab_common.c index 40b582a014b8..fc698cba0ebe 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -392,6 +392,19 @@ kmem_cache_create(const char *name, unsigned int size, unsigned int align, } EXPORT_SYMBOL(kmem_cache_create); +void kmem_buckets_destroy(kmem_buckets *b) +{ + int idx; + + if (!b) + return; + + for (idx = 0; idx < ARRAY_SIZE(kmalloc_caches[KMALLOC_NORMAL]); idx++) + kmem_cache_destroy((*b)[idx]); + kfree(b); +} +EXPORT_SYMBOL(kmem_buckets_destroy); + static struct kmem_cache *kmem_buckets_cache __ro_after_init; /** @@ -476,9 +489,7 @@ kmem_buckets *kmem_buckets_create(const char *name, slab_flags_t flags, return b; fail: - for (idx = 0; idx < ARRAY_SIZE(kmalloc_caches[KMALLOC_NORMAL]); idx++) - kmem_cache_destroy((*b)[idx]); - kfree(b); + kmem_buckets_destroy(b); return NULL; }