From patchwork Thu Sep 5 07:56: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: 13791886 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 4E9F6CD4F59 for ; Thu, 5 Sep 2024 07:57:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CBAE96B024C; Thu, 5 Sep 2024 03:57:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C69E56B024D; Thu, 5 Sep 2024 03:57:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B16276B024E; Thu, 5 Sep 2024 03:57:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 9051C6B024C for ; Thu, 5 Sep 2024 03:57:30 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 4E8C91C39CA for ; Thu, 5 Sep 2024 07:57:30 +0000 (UTC) X-FDA: 82529929860.23.3C58ECE Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf24.hostedemail.com (Postfix) with ESMTP id A0CAB180011 for ; Thu, 5 Sep 2024 07:57:28 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=rMBdS4oJ; 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=1725522951; 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=CBanIYb5JGGWWLG7NSbIZ428b0/eJ74MvZXXRmhCRyY=; b=lYL6agMvDfB1q1/jNuWYf8ZJm0RC8telLVa1ewF6nW1U8bkqaO78bp4Mc6rQKFahr6/FXl 93McC82HXvnfcfo7ixw+EHsFCPjG6p8qG7tBd+V9w+DL17f/pTyQQHE89LFmlmVJsBBGph 5MNrO1JgVrFjkwj5RzVJLtimUuFY7i4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725522951; a=rsa-sha256; cv=none; b=e2+2FFqwyCkMTlj1SFpbd9sm6qvsjMghLx/GhzCBMoQ/zZFYE5b/GPSJtfKeJrLTKpKDXh dykoAFhRZBqv8mxbOSk/yRbJSVAw4n/jICoZVQk7mC6o4dcSjz8XOX9+o+3mcX8pYlPFrO FlG1ppcjeNnulg6ZVhFIwpZInChBJp8= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=rMBdS4oJ; 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 B932CA44372; Thu, 5 Sep 2024 07:57:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E314C4CEC9; Thu, 5 Sep 2024 07:57:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725523047; bh=9LaPebyH3fPMvl0DXSpF9bydw1rDuiO92393crLdD6M=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=rMBdS4oJXDrqT8tGREWQUTOIfMJ/VpD19pMK7GmE6v97b4Pb2Y4v9LbtFL42rZbSy 4QLWYUCZnCESDH/lYq7gVT5xSfchSm9rP1Ofd5fEPA7M7Wjc9+OPwFMuXcpMa7ljRv GUDOr8RdXdjIa0ysmqgYVYyGSdZxY3Z9pMKAihH1fXR6lcUc95iKW61EhSVTEjOyds gES6UEM4ZLmYRj3x+nBKmtXAjTT6EXs3Z0nP61/sxeR7GFRX+B9EcWB6o2EttWLYgN RNpJMAHt4PanxiTjwkHRzn2t8D/GfFIUrR6crlqou9TzXGGzhaPB6DRa061E56J/dM 7Tsat6ATNJ5/g== From: Christian Brauner Date: Thu, 05 Sep 2024 09:56:49 +0200 Subject: [PATCH v4 06/17] slab: pass struct kmem_cache_args to create_cache() MIME-Version: 1.0 Message-Id: <20240905-work-kmem_cache_args-v4-6-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=3238; i=brauner@kernel.org; h=from:subject:message-id; bh=9LaPebyH3fPMvl0DXSpF9bydw1rDuiO92393crLdD6M=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaTdTPFKWG33zVhlwrtNldGc23ao7HF5fPuMy6fDemo3L XaX5PbN7yhlYRDjYpAVU2RxaDcJl1vOU7HZKFMDZg4rE8gQBi5OAZjI5PMM/zNOmF/zC1hxZfra wDv9x4K3Xj5x8ceq6VGXD3d4/53qLBvEyNDsvTPy8Bf1+vmHhXb4LUrTW6rm9nr9y7yK7SaaFuY zX3IBAA== X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: A0CAB180011 X-Stat-Signature: 1xxtbfbnyysujzjaa183aawxpmz3qy1x X-HE-Tag: 1725523048-501136 X-HE-Meta: U2FsdGVkX1/iS75DYZwmQfigYE8wi2eK8JPEiyyLVwvPw8r1jCvT5d0wLIzYuQ9vNzLTH3jEZrSW0cXlbgNY6kGqAivzhmiu6j8f3CDHYnwQJtM/1TaawMMIDNnwSTn2iPZA+2W4OS45rW+cgtYJf7SLBgu7Yg2QvHLn5OyxaULtklx4a/z8uL0cuCfFIRpNwTZwdb345Hk5uvkDghaNIqyHMSksjUdOygoG3MlMiC6cC5jP7fLJYrsCJE1gfAdekmAK02YIB21skAXz6S5FSU+s1smKzNXcaIGZob3kMibBhvm+kAJQRthSwbm882lJqTqLW/ekbdxUHNtZe19KzskSyQoA7eXehQriPKkdZy0WI7AY4/uPc6uE7lcNRYfZDBfzj6ajuJaNjhh8dmbMGmq+rLjzHAK4x0jozSxlkJoKmyWWEkxe1wExk80BTxzs5HpJeXKaszTrWnUYf4LxZ+cikY0kLbNv0S58VOOc10VwiQV7MWmzdKowU+WMdAp48pJqhLr7mG+lEqc6HxE35WMipVDkGZBTCooX6T7panHzwJeSZuHqlrAHUsjPS2GsqTIkpN7+2maO8QL3gw+x0y7owAlTjmibkEktPkcCDKsH+kTTqik3qxnM5kBiLFRZH1RMJ7rH0MRF6CgstcHmPBwTwBjmdjv+kV35UhFyHt8jJ5XdM47qD+vluYdX9eUCjzBmF7XNIG/ntHmahgI0EDDi8uGGRp+GF5RzBEBJMqaGJMqZMypYZEQKiAOaLn0bHJUM9BqJRign3iePiLcb2XjgKwXbeGTD/cIRmxRPAzCD+3fMNZmsGrhDn+k2CtP/g3thxULu1aUa2UPgxqoOnxIQrfiXmFOzB3qONDAjLMAm9Iws36WSs8Pn1hU1oXURtORme4NoKxcAlC300k8+BIEqGKNuIHA0gWnEwr291G8x7W5UBOpgOVEVbxylZ4Bm8FWt0Jp4YPepUm5dOyv QUMa7Ci5 78+UNiLMs0F4o9Hc22GOfQ+2tRaJcD0L+34RazTjOWr9GnKDTKSrhMbvZDAPXEvxmLPLarIehHN+50CmN3sBwFTjhF1NpVQfNOMSFnwqIayaJnfNza8Xc/NwvZqME64tmUw6VGuxupLF5N18HsNpOpDuervg2jXgwo6Wrr2brMFo4hsAiH6QO5n9O7R1djy/9gdwzLVgwCp0CMXVMDIV1NQN4yIihlx6zbOE4zovr8SfVi+103U4nOmMLBM/skP1kR76aLfXUI20r3AheMrv3Fdj+gIeIYVfFGtUyxIibU396KmOfbxrtFIbRTZpK/26+Zb4AgkCCXSVaXThyIIELltCRpl8CoEb+/06G9nNWJfhGdJ75xL0lobN+XdPDttH1xxQB6S7kjt7qcBNuxKHfhJmWTvJhBQ9hAE91 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: 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_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);