From patchwork Tue Sep 3 14:20:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13788790 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 7C416CD3439 for ; Tue, 3 Sep 2024 14:22:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9204A8D017E; Tue, 3 Sep 2024 10:22:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 885BA8D0151; Tue, 3 Sep 2024 10:22:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B15D8D017E; Tue, 3 Sep 2024 10:22:44 -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 3B6BB8D0151 for ; Tue, 3 Sep 2024 10:22:44 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E319BC03D7 for ; Tue, 3 Sep 2024 14:22:43 +0000 (UTC) X-FDA: 82523643006.22.10DAF3D Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf24.hostedemail.com (Postfix) with ESMTP id 2F15818001F for ; Tue, 3 Sep 2024 14:22:42 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RsLWeAqc; spf=pass (imf24.hostedemail.com: domain of brauner@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=brauner@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725373267; 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=47AOvIePKm4VA+iqk58/MZHnc36sqtLPgyX8VJocIiA=; b=x4aN72ZvYtGmjSH+QER5LglMysbMOvfGU5aPY8gfec0lVu2Ks1+/moavOFSwUO9vwwd8jt DUss/Sm/K1Beu+Eo/7sUDt1xqucCJRdM8XPfz9FogmR5Tj6LyacCjSZ4NlkqNXVhK2awg1 aeR9cni6WFHGYFx8S7UB7B5bg/NFBfA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725373267; a=rsa-sha256; cv=none; b=Yv6hcvF5FrNu06XLBV/yOUXHWrh12Se93Jm4mXG4UBHq5yvfn3e39AYnr7r2TNr9/ZIKct bTjAcVfVvGQM5q3+23YxfW6xVmUumbJcoH06xYk2umZZT1TTirR4ZYafvjHDosLdB4z+yg ADO4dp+AyojvyxKBcwUQ/T8Lr/cPyXQ= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RsLWeAqc; spf=pass (imf24.hostedemail.com: domain of brauner@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=brauner@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 64761A4367A; Tue, 3 Sep 2024 14:22:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8786DC4CEC4; Tue, 3 Sep 2024 14:22:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725373361; bh=LGtj/e6uWtTAC/2FfRENwjsuEXl8qpeXQfpfD6hAo/g=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=RsLWeAqc+DgpjX7fIXp3seQzC7Jou5QA3YNKQA96AB5ngZNz4PJaisGMq3sCixh5r QOgA1QJdHZQNaRLR/leMrddYpzKBCE8vWScxNK+YiFqISZSXv84tau6h7mXHEVcpr0 HJYqlDlVWjsSc0SNm9i+pXjDw6ODPRoFutRQQfM3i/wA8qynyXkDQggEHsE/XfNbm/ mjXtmxEjDfgHqwCzhhcHS3NajIW1E/l41DICazy+Jl/afIq9+LHEEQ2buTp2tP1QlJ 1FKl0p/6/MdN+LRySJdd4+H+ILs5xRe5Gg8ifJHwc11AtaWaRaI8iB+luaLgDbU7YU N8CBqhbYiO10w== From: Christian Brauner Date: Tue, 03 Sep 2024 16:20:49 +0200 Subject: [PATCH v2 08/15] slab: pass struct kmem_cache_args to do_kmem_cache_create() MIME-Version: 1.0 Message-Id: <20240903-work-kmem_cache_args-v2-8-76f97e9a4560@kernel.org> References: <20240903-work-kmem_cache_args-v2-0-76f97e9a4560@kernel.org> In-Reply-To: <20240903-work-kmem_cache_args-v2-0-76f97e9a4560@kernel.org> To: Vlastimil Babka , Jens Axboe , Jann Horn , Linus Torvalds , Mike Rapoport Cc: 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=3814; i=brauner@kernel.org; h=from:subject:message-id; bh=LGtj/e6uWtTAC/2FfRENwjsuEXl8qpeXQfpfD6hAo/g=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaRdl57zp/8H58sZpdqnOv5v877EcHrts//a9Txn2or0d 272eOaU1FHKwiDGxSArpsji0G4SLrecp2KzUaYGzBxWJpAhDFycAjCRDW8ZGTrXHOfxNkk++6Bu Ud50/7Xu9itYrLle9Rboh6fcuH56Axsjw7cazcD7wjNt1i5aLMG87YLj89YNW27YnctQMQqyfjp Bnx0A X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-R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vwcoJ1/yNWhMKC E6ZKZ5gl Viwstd8wj4QVOCychbARtmAeksGuHjtZG2eihApSrtmCsvdZ9rvT3g2KYJu06ogor+ubSQ5C5PXOXU3fj4bkCW+DFkNxbyx7M4pwTXDGSfWAfq1porqgByPTGwZaj7D2jwWPMzA/7zWfWYsHJ0Qp6CAQeSVJ87oJjU3fd5xGqmINcLzppvf28FhR8FbluywOT2iXHaf43HInYcyWClOMRCaEyMc+PYZ2/vyyGJyUyD4hWm82ilsivaXtimSuk+i/+I4Km19EQoCXqtGBV7or83vezV9uzTh4a/10Y 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. Signed-off-by: Christian Brauner Reviewed-by: Mike Rapoport (Microsoft) --- 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;