From patchwork Wed Sep 4 10:21:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13790359 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 DFEEFCD3431 for ; Wed, 4 Sep 2024 10:22:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 73BD66B0317; Wed, 4 Sep 2024 06:22:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6EA8A6B031A; Wed, 4 Sep 2024 06:22:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 53DD96B031B; Wed, 4 Sep 2024 06:22:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 33DC36B0317 for ; Wed, 4 Sep 2024 06:22:18 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E95E7120F44 for ; Wed, 4 Sep 2024 10:22:17 +0000 (UTC) X-FDA: 82526665914.20.C836C6B Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf18.hostedemail.com (Postfix) with ESMTP id 225921C0012 for ; Wed, 4 Sep 2024 10:22:15 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RcQXs353; spf=pass (imf18.hostedemail.com: domain of brauner@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=brauner@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725445287; a=rsa-sha256; cv=none; b=CKup2zJJncF0f/godtEqqAdMlwiQuQLdGQxQiUeFvNa+CXc65WmKlunJ379Agbyh2thhPZ CUYiBHOnF259XuSAAFHo/A8elNzIlwGSKsiRTitOwwHR5YLNa7XMwAjfH7EzRcdJ5qu0WB DpKRtDoGBTJdfecFZL5TuLlfblH05Mw= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RcQXs353; spf=pass (imf18.hostedemail.com: domain of brauner@kernel.org designates 139.178.84.217 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=1725445287; 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=o27A/LKlbOJ7Sc9aB+05j+9dGVu2UPSc5F+bSicdO6M=; b=EGVoZ92baKY1KEL04rp8ztUVwQW0KBguKHogE7OfIi10XyQghlwBdK7G341VLbwA59ocx8 9h97R4K3dm7fXuKxF7x73pESfbUmDJ5NX+AEOpGCzZ6/ozjLtqxnetWbtrVuFTB+aJY2EI kif9wcMpJIkHRcDefISue3WdfCCUNHA= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id D22545C56FF; Wed, 4 Sep 2024 10:22:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84756C4CEC6; Wed, 4 Sep 2024 10:22:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725445335; bh=wlErePvTE8gEuAQI7b5rPaz+icXnXkiXiNHwXkcPVSE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=RcQXs353asnqMtizb8ucN9fB/kmrdEonJJa4WhFzECgl1zSEYCask+0iHaYbU7A0z +WT8J2sxrWx2DYfPN/Wp0oJO3cpPXzoGsp6g5FhdnDbxO7BgD15iCDZh8iC6F55AX6 tfdEmhho3yPQgkUQ8YDVdjVp/rtS5mItx6Tzp19daAiBkCSHovIv67mP8rvt+HVn6u iRosz7EPbnsH157G/WRr7qwowiavGfbdahCmEcloUYfOv6UIpynTERb7ORi/fbyqXc U9GjQr7pb/4Z0r01sVOv/ezRE6PGYyMPqa3bv3wOEPhXC91/lNC6Z+GVtwHG51Fwnc jofw4P+pfNMZw== From: Christian Brauner Date: Wed, 04 Sep 2024 12:21:11 +0200 Subject: [PATCH v3 06/17] slab: pass struct kmem_cache_args to create_cache() MIME-Version: 1.0 Message-Id: <20240904-work-kmem_cache_args-v3-6-05db2179a8c2@kernel.org> References: <20240904-work-kmem_cache_args-v3-0-05db2179a8c2@kernel.org> In-Reply-To: <20240904-work-kmem_cache_args-v3-0-05db2179a8c2@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=3153; i=brauner@kernel.org; h=from:subject:message-id; bh=wlErePvTE8gEuAQI7b5rPaz+icXnXkiXiNHwXkcPVSE=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaTdMNl1R3mW7FIn46d5Uw7FCL8OX7j68p7IPTOUeZ6nW fQ4evzz6yhlYRDjYpAVU2RxaDcJl1vOU7HZKFMDZg4rE8gQBi5OAZhIkQrDPwMljWLOnBfnlr85 ev34+sX3utvinm91l5RrsfgnVFdw8S3DX5meJ8+41y4wiH14V6ymv6fdjn3j+rfRbbdULWL17pj WsgAA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Stat-Signature: cgj9ej1rdnagazqebd8uf3pawdfp4er4 X-Rspamd-Queue-Id: 225921C0012 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1725445335-449382 X-HE-Meta: U2FsdGVkX1/pbKpRv5apLRNT2/jjJwh4v3HV4EZwy3dVQj2HFFKNh52qr3mpI3VCDJbHa2pcW0qX3bJVuIQUo3NEIB6w6By/rX2sVFn2PzChWOV0fOxj0xHZ2LhVosASUlfr55ilBLXoQoWGJpVott6OdL5pXzk9ejLkqh85VuqU4ZVzAD+Nd9F8oBEJLf02GoG5FJDHMIhIit2hP/yfeBl/SJ8uXJaZ6BGqJfVaG37InBkEFLduIgrsMP3JG+QrH/cE7+JAHQePAymGntvga7arbUjry0ka/FGNRidfWC2s6ECTHc8mi9fAvUB9xhR1gHXe0HuzT383qZFn5B2uG7iN2oeDRU015uKWog9ZHFAqkRaBm53DEnGhCYwFESalNfDNFrQbEil2qpNO2Cg0Ge9KmK9x5NV7On797cVaX6ZcZc4fWn2Phl29dsIzlahioAMDcR1Nh899kI5TWt5rGcXxV9UxDsjKKMl0+e7LVwLXxHsf1I+DpVfgqTodXviEZjCsP1bgI/KCPLIdlLFwQPgKdVXY88vtRPrkkZBN9quBq5MbHlAdRKizDSDJWgrjJZ3JSAK6eJnRDliw1yO2SopoIa8WK3nZaH4xMOUyUi7EkO1EhjXivaEq9NTf8WkgbLeZzEPqmynKhF9H57AY6OitwAI1CKxn5HG0RPPGiZ0ocPyT4F75Cu75z02VLiVANgQyVMUzdRmxd63SNN7y4bN8C4WVUTPiYq9kABsqCcWp9GrzvJJHpLhy2MkGO1LkBfGq/rCFuRcVVAEsR8azp1njVI6cKQbJSdqSNK4Rdhe+AW/kcMpNE13du8sS/FnmIzkCMMtQ44OBJcd4sSFBxGOoYEaOg/rJSydV1G3TirWEX2NYCIA1mR/QB5SLqim4OAavbNrWjSMmRESjl07pg9CrdESuzaGa2Uc35xhj3cghmqC/Xy5gQzpLamE3jjYGEyDjz/SVQLj07cWh1I0 Z8mbpshV G9m7BcQg+rX22/JoJFuNbTWTQZw9LFHh5cQlfts8/vcH2zCXcoQRcQGLQYYhnrEeVDALjCifQK94EHpFdxoggO7bfHkK79/GjTpmEtb/D4rLX51LuJNhcpIK03rpWQZ9XwZ6lpGe1i2DEUiDCUIr32nTUoAUk09BehKK6smvqOb7wH3c//b8xWAGNrktWa/+H0oarXIzsmmmdoC4IV9gPZUfxcQBl8zk8QM/FEP/ooKSxKtxu/V+sWdCYEyceWvNiyOaLAaMMU/DdCjn+LBaJV25Fe6NHiZL13MP7bDatqArczjobGuFY4OEVUScyKPxhylAIJUmKTvfNWvsIGwFDrCXKPhLlaHGinytTzsJRV5SmStU= 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: Pass struct kmem_cache_args to create_cache() so that we can later simplify further helpers. Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Vlastimil Babka Signed-off-by: Christian Brauner --- mm/slab_common.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/mm/slab_common.c b/mm/slab_common.c index 16c36a946135..9baa61c9c670 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -202,22 +202,22 @@ struct kmem_cache *find_mergeable(unsigned int size, unsigned int align, } static struct kmem_cache *create_cache(const char *name, - unsigned int object_size, unsigned int freeptr_offset, - unsigned int align, slab_flags_t flags, - unsigned int useroffset, unsigned int usersize, - void (*ctor)(void *)) + unsigned int object_size, + struct kmem_cache_args *args, + slab_flags_t flags) { struct kmem_cache *s; int err; - if (WARN_ON(useroffset + usersize > object_size)) - useroffset = usersize = 0; + if (WARN_ON(args->useroffset + args->usersize > object_size)) + args->useroffset = args->usersize = 0; /* If a custom freelist pointer is requested make sure it's sane. */ err = -EINVAL; - if (freeptr_offset != UINT_MAX && - (freeptr_offset >= object_size || !(flags & SLAB_TYPESAFE_BY_RCU) || - !IS_ALIGNED(freeptr_offset, sizeof(freeptr_t)))) + if (args->use_freeptr_offset && + (args->freeptr_offset >= object_size || + !(flags & SLAB_TYPESAFE_BY_RCU) || + !IS_ALIGNED(args->freeptr_offset, sizeof(freeptr_t)))) goto out; err = -ENOMEM; @@ -227,12 +227,15 @@ static struct kmem_cache *create_cache(const char *name, s->name = name; s->size = s->object_size = object_size; - s->rcu_freeptr_offset = freeptr_offset; - s->align = align; - s->ctor = ctor; + 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 = useroffset; - s->usersize = usersize; + s->useroffset = args->useroffset; + s->usersize = args->usersize; #endif err = do_kmem_cache_create(s, flags); if (err) @@ -265,7 +268,6 @@ struct kmem_cache *__kmem_cache_create_args(const char *name, slab_flags_t flags) { struct kmem_cache *s = NULL; - unsigned int freeptr_offset = UINT_MAX; const char *cache_name; int err; @@ -323,11 +325,8 @@ struct kmem_cache *__kmem_cache_create_args(const char *name, goto out_unlock; } - if (args->use_freeptr_offset) - freeptr_offset = args->freeptr_offset; - s = create_cache(cache_name, object_size, freeptr_offset, - calculate_alignment(flags, args->align, object_size), - flags, args->useroffset, args->usersize, args->ctor); + args->align = calculate_alignment(flags, args->align, object_size); + s = create_cache(cache_name, object_size, args, flags); if (IS_ERR(s)) { err = PTR_ERR(s); kfree_const(cache_name);