From patchwork Thu Sep 5 07:56:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13791888 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 596A2CD4F59 for ; Thu, 5 Sep 2024 07:57:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E1AC36B0255; Thu, 5 Sep 2024 03:57:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DC9AB6B0256; Thu, 5 Sep 2024 03:57:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C46B66B0257; Thu, 5 Sep 2024 03:57:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A51846B0255 for ; Thu, 5 Sep 2024 03:57:38 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 5E3D51A0A13 for ; Thu, 5 Sep 2024 07:57:38 +0000 (UTC) X-FDA: 82529930196.26.3804D5C Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf19.hostedemail.com (Postfix) with ESMTP id 961F01A0004 for ; Thu, 5 Sep 2024 07:57:36 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=lCMJJsA2; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf19.hostedemail.com: domain of brauner@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=brauner@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725523032; a=rsa-sha256; cv=none; b=fcL+D4fD1WUSlJV17NSxvqSzS76quluMKTjrAthbzLRnvkdzaaRkoCNGsVrkcnLgzGT1Oo abhHIVA59NoEPmWH/U7ldYmx8HLTD8O0e10qsLSIUDpdXpVU/zGD6Bd1Wrxf9qFtS8CbxV fDlNdtsqYMNdz5ZQA2aIZuR56v3nd2Y= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=lCMJJsA2; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf19.hostedemail.com: domain of brauner@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=brauner@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725523032; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ID7KRmdzDAcphg/Ijv1Oxd4c7RBfeOynWnxC9R+BJ48=; b=egVPsteBO1DxIEVqPIikJWnKf+dERPXczkQSHfPbW7UKAbu9a6rOizqwWdf/06BmBgMXjI JglrbT1bTLmf7mQijNWnQZNqto5VU9lN2Dz1N/+1m/yVh0w2ZwfOgLaiCeZDSJxQrTTa3v jfRkP+Fwy104EdcTp+j34GJbvcr/4iA= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 640C35C0F8B; Thu, 5 Sep 2024 07:57:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28B9FC4CEC3; Thu, 5 Sep 2024 07:57:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725523055; bh=68ks3+RK7luxREXLt0gNfsWbQ+8I8NfI8y27/qM8GTo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=lCMJJsA2FYQgZ241Y/sVm4oECKak0msryTpe6Sxy0xhPqrJ4bz+KhoUhxL14XWa1c 7E+aemB9oTGTfc5vf7ZjV6+34ksKJNjfyrwdWGGVBINGAM5bGQEHyfHw0aanRFgDfr 95fU5OABVDgKWclGHd20xyuZDsq+ffWmV7zDnzjhyo5D2a+9PoWQZhHl9tt8+dkT7Q UJVo/ISOhmxyzB8f/ZerRvzWyNLDq9UE4WkJcK7GI/AN2FVNQ96k1gBj2pqV6egzIm iGbxOz4BJ5tXpM1QhItXBzVswa4b1k2vJkjww2yuXsrYFWrJ7pQlGvB8rpGUrNO8TA TsQJqs2fi09KQ== From: Christian Brauner Date: Thu, 05 Sep 2024 09:56:51 +0200 Subject: [PATCH v4 08/17] slab: pass struct kmem_cache_args to do_kmem_cache_create() MIME-Version: 1.0 Message-Id: <20240905-work-kmem_cache_args-v4-8-ed45d5380679@kernel.org> References: <20240905-work-kmem_cache_args-v4-0-ed45d5380679@kernel.org> In-Reply-To: <20240905-work-kmem_cache_args-v4-0-ed45d5380679@kernel.org> To: Vlastimil Babka , Jens Axboe , Jann Horn , Linus Torvalds , Mike Rapoport 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, linux-fsdevel@vger.kernel.org, Christian Brauner X-Mailer: b4 0.15-dev-37811 X-Developer-Signature: v=1; a=openpgp-sha256; l=4004; i=brauner@kernel.org; h=from:subject:message-id; bh=68ks3+RK7luxREXLt0gNfsWbQ+8I8NfI8y27/qM8GTo=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaTdTPHe0MpoGSi7d66U3P/akqWzzBdPLC8ol1nexlAr+ ncn67pdHaUsDGJcDLJiiiwO7Sbhcst5KjYbZWrAzGFlAhnCwMUpABOZeoPhf8l6tcjWzRWT1WbF 3H4W5XN1Ert36Ee5VbJvw3KvM/h5v2P4xbzkMcfhuDniFefderU3aERvNT+tKWEXWZq1K9iyqaC YBwA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Rspam-User: X-Rspamd-Queue-Id: 961F01A0004 X-Rspamd-Server: rspam01 X-Stat-Signature: fs9p1hw6ax7rzfn9fr99oxx868ncrasm X-HE-Tag: 1725523056-541096 X-HE-Meta: U2FsdGVkX1/tSg8c3e/nDbrZLxWtY9sVYDgJLlSjN+k8AXaQrFfg693Kt+ZDrgdzIzPG3YayVNvneD3Hx4RIsCJxPgPn8YKj3JvxzSCCJydHqTdtq+c/C3lCRcon3SCtQwHnG7Zd28PRAexehyScjAPpOT1ghIijjptgzFceDiG7t2VJteZtp7wdEamB12QekdaL5717CNOn4lgKbSvoctaxD7RIn7AB5C5+fW0u//tyRrWAjvoui+52ZsFSNcpugalbZVZTYMBp5ka3iqOOIFVMIoFOORghFz8byPjpl/B4RQQFtvMA/HHARMfak6QIpw14esBtO2+aGzRDZE3R0B/WulJG7UWRnX8NAbmHH4c3jo8p0Ax0T3796ujX/FgD3MeoNW2pL0xMi1gG2zFywGtyTsNd7PvaysMKNEu6andeBX/9+x8jnX2s6AhZiH90M8JX+UcsOOPOWyD1LXglxD4EcUFar2Z8K7WkACXsffXL0+8bBh/UarEcWeoYiNjdlxXOEX1nkefe4oWXkMTxxQZ6tb7wUWE7TegHyxepReYx+eSnf2MhpXgPbdymk7jNsjHZSzOVObqaOWcdbs0tu4h+gjWKEJTs88liCv95G1uLAsEg12/EJIDqQuYtWMskECamaMWiAXmt1QsNR1cvUVpVTRXb8/C65OLQ9EXsh0Dnf0AxLmtdiuverSCg1EQ3UEQgWpz4M4gCsdMoVLts4KDi/8xja4nSWtE+q5uCPhbC2vSxIirahvRFHXocx+p5cgfK3vOPj+drut8if2N+DdLfJQ57fou0fsAZdxnilQ3y38PW3JsxQanHV5n10XCUpFfHdaIK4+3yFMTf9lG3ziIkEgcwvKr50Gt2IGKvsHDQb2OEx0i05LDUn8c2WCtz2aSYYcAROLNMFNoLmPP7+HYhbO6tjPlwBksosBVKcM2bGYMqiT2rxJw6iNBMsXXD9xcTYqHHyT5voxoyy8m M1c9Rwkk jImt5Hu60Rv1nTFAH3t8e6PnXbKknjAD/yS6QAa49+JshDGwnKyzweBuI/xhqcNKm35/Ix/5vUMR1eSS/nPrKjoRkhZcztUM9kWT+l0LomHsKMMVlQYxiviyQt/yEzSaUF78qgzYOz8BKldyhqKSyk0Phsed9Ko1CYZs22eXRgYoFQpAoqpSJJ5eFqNyq+N4NSh1Di8EYY0MnUnyyF4FrdFkxGVi9rxZK+bHRMYu6gKh5vtH3bR9AoBjqCmIK9kiom8WtJXPZJSuFXGsLBDOn7CunZUMWjtUvc7kmNFTiNa9mFiQF9X3X03O6NLYRb+iN9eRukzMbPr/HkFEGBCR2If/RHSeteByh6V2/Ucw9IKs6NcrPhMxuSSn1HA== 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: and initialize most things in do_kmem_cache_create(). In a follow-up patch we'll remove rcu_freeptr_offset from struct kmem_cache. Reviewed-by: Kees Cook Reviewed-by: Jens Axboe Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Vlastimil Babka Signed-off-by: Christian Brauner Reviewed-by: Roman Gushchin --- mm/slab.h | 4 +++- mm/slab_common.c | 27 ++++++--------------------- mm/slub.c | 17 ++++++++++++++++- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/mm/slab.h b/mm/slab.h index 684bb48c4f39..c7a4e0fc3cf1 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -424,7 +424,9 @@ kmalloc_slab(size_t size, kmem_buckets *b, gfp_t flags, unsigned long caller) gfp_t kmalloc_fix_flags(gfp_t flags); /* Functions provided by the slab allocators */ -int do_kmem_cache_create(struct kmem_cache *, slab_flags_t flags); +int do_kmem_cache_create(struct kmem_cache *s, const char *name, + unsigned int size, struct kmem_cache_args *args, + slab_flags_t flags); void __init kmem_cache_init(void); extern void create_boot_cache(struct kmem_cache *, const char *name, diff --git a/mm/slab_common.c b/mm/slab_common.c index 9baa61c9c670..19ae3dd6e36f 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -224,20 +224,7 @@ static struct kmem_cache *create_cache(const char *name, s = kmem_cache_zalloc(kmem_cache, GFP_KERNEL); if (!s) goto out; - - s->name = name; - s->size = s->object_size = object_size; - if (args->use_freeptr_offset) - s->rcu_freeptr_offset = args->freeptr_offset; - else - s->rcu_freeptr_offset = UINT_MAX; - s->align = args->align; - s->ctor = args->ctor; -#ifdef CONFIG_HARDENED_USERCOPY - s->useroffset = args->useroffset; - s->usersize = args->usersize; -#endif - err = do_kmem_cache_create(s, flags); + err = do_kmem_cache_create(s, name, object_size, args, flags); if (err) goto out_free_cache; @@ -788,9 +775,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, { int err; unsigned int align = ARCH_KMALLOC_MINALIGN; - - s->name = name; - s->size = s->object_size = size; + struct kmem_cache_args kmem_args = {}; /* * kmalloc caches guarantee alignment of at least the largest @@ -799,14 +784,14 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, */ if (flags & SLAB_KMALLOC) align = max(align, 1U << (ffs(size) - 1)); - s->align = calculate_alignment(flags, align, size); + kmem_args.align = calculate_alignment(flags, align, size); #ifdef CONFIG_HARDENED_USERCOPY - s->useroffset = useroffset; - s->usersize = usersize; + kmem_args.useroffset = useroffset; + kmem_args.usersize = usersize; #endif - err = do_kmem_cache_create(s, flags); + err = do_kmem_cache_create(s, name, size, &kmem_args, flags); if (err) panic("Creation of kmalloc slab %s size=%u failed. Reason %d\n", diff --git a/mm/slub.c b/mm/slub.c index 30f4ca6335c7..4719b60215b8 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -5843,14 +5843,29 @@ __kmem_cache_alias(const char *name, unsigned int size, unsigned int align, return s; } -int do_kmem_cache_create(struct kmem_cache *s, slab_flags_t flags) +int do_kmem_cache_create(struct kmem_cache *s, const char *name, + unsigned int size, struct kmem_cache_args *args, + slab_flags_t flags) { int err = -EINVAL; + s->name = name; + s->size = s->object_size = size; + s->flags = kmem_cache_flags(flags, s->name); #ifdef CONFIG_SLAB_FREELIST_HARDENED s->random = get_random_long(); #endif + if (args->use_freeptr_offset) + s->rcu_freeptr_offset = args->freeptr_offset; + else + s->rcu_freeptr_offset = UINT_MAX; + s->align = args->align; + s->ctor = args->ctor; +#ifdef CONFIG_HARDENED_USERCOPY + s->useroffset = args->useroffset; + s->usersize = args->usersize; +#endif if (!calculate_sizes(s)) goto out;