From patchwork Wed Sep 4 10:21:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13790365 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 3E17ACD3431 for ; Wed, 4 Sep 2024 10:22:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C45628D024A; Wed, 4 Sep 2024 06:22:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BA5FB8D0242; Wed, 4 Sep 2024 06:22:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A1FC58D024A; Wed, 4 Sep 2024 06:22:41 -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 832A58D0242 for ; Wed, 4 Sep 2024 06:22:41 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 26F7B120F5E for ; Wed, 4 Sep 2024 10:22:41 +0000 (UTC) X-FDA: 82526666922.02.1367C57 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf15.hostedemail.com (Postfix) with ESMTP id 6C2C8A0012 for ; Wed, 4 Sep 2024 10:22:39 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=HhZh9DXp; spf=pass (imf15.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=1725445283; 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=F0D9YABQJXkuctn4M92D5YWV5HVwbeySEi/bw/8C2FU=; b=YfRUTgEUCUuUUAXXTtFXJZNTnqwjLlrOS7N5zJgWjN3dt6Rq5HEJlIqzhZJzmsDJIzHOJl q4vT86DLiYSWMnEY+YWhEwMAGA0ARU9o/qYC+vgWqloW54yZsFrslvcYMijdB5QaNoqst9 gMI+ympCv2fWzgi4wX5zRsi+8ifFVlg= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=HhZh9DXp; spf=pass (imf15.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725445283; a=rsa-sha256; cv=none; b=qspTKOB+WnUPAAQ8xL5Opml/2MZtaRLKJUaF4XS04L9PJgu3iK6+1zj6VBB6ihr8pB790I RVsCZ+t1LLdEWAUta8VMNrqR8U+rKIk66HBrV7fWUVJJOaAPu9V1XpfeIlNlst4+SL74yH rBuPWklB4DRJQGEuyMe8e7VupIHU2sM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id A24F1A4327F; Wed, 4 Sep 2024 10:22:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F26DAC4CEC6; Wed, 4 Sep 2024 10:22:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725445358; bh=dnwP/c5HlqpuuYs6TocRpCymaBfpftG+kdwK6XKc1E0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=HhZh9DXpXCPba9MpQZVKOy0Ru27OS0HEskSXwAoDug2DUBzvgpz64S98j7Hw1t/bC BVj+HYC6e8qqlAqINxPAkWw3OhJM3Ou2+TOjNYfe+EPeKyLXxkaN31I3Uo6sUMGr+9 MmCk+iSDrssxm7ruDUw4wx6fAOPkz/++IWZjV1gD66ymm4gV9WFq+aOJGQH309H/7M EFpGvoa7aVx0dDTnBfaX01Bd5+U3LjFbuYSjbLn/nqf9tHWtEepUycPqo+VXfDFM8L 9BehLMX+Y0F3ogbV8kHXUl0vnhsfc0ExXBSSmNz5GI5GDFX0yUHmZeScAnze6TYIEU NN53xl5rTni6w== From: Christian Brauner Date: Wed, 04 Sep 2024 12:21:17 +0200 Subject: [PATCH v3 12/17] slab: create kmem_cache_create() compatibility layer MIME-Version: 1.0 Message-Id: <20240904-work-kmem_cache_args-v3-12-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=3373; i=brauner@kernel.org; h=from:subject:message-id; bh=dnwP/c5HlqpuuYs6TocRpCymaBfpftG+kdwK6XKc1E0=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaTdMNl15rbBxssX1ASll7Ntr2iuelPPt6tHsviFY87f+ 97vVoi4dZSyMIhxMciKKbI4tJuEyy3nqdhslKkBM4eVCWQIAxenAEzk7g2Gv/IhxWev+F9Q+PAl 1O+De+AROQ+p2wpTl6p7Js2erjNNvoLhf7Z27Q3zJWyBfJVrtRhcdZ/UPjV03BB5ksl+6sHqBXl 5bAA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Stat-Signature: podsfogszqgk7pnk5wrg5jrabb4unfpb X-Rspam-User: X-Rspamd-Queue-Id: 6C2C8A0012 X-Rspamd-Server: rspam02 X-HE-Tag: 1725445359-90973 X-HE-Meta: U2FsdGVkX18ZxXUxz7eNFQMcftDdNjLTFo7j4QTE9AA1xcBjeoL0XVzua6U7kl88iojLVBq6YBTndUiarL6TntqybQ7o//ivc4lC0vIgyCVFgSXSNOkX5kUja6jYh9QZKtxqM2FK7E+9GP1yerdAuWw9COAQivikg3JbzbLayZH8kLye6Kvr/pVLoEn1ZUepP34rGJ53TVw97tt4VXrb2vWKZ2lRVO6QXYE12e3kMyFp+gvCvH9WRFOJvQrroxsNLTpTCsKtctPgwwGNFMDqV2lSeiVM0FHNNVdc7SF2CortZV9AgDNxJ3SZ15hgxYClhFqkALNHUzKY+BxYDb/qa+bdBjV5uDPbR6FKSSVwKLCA6RBoxM14Nzl47R/7kUVY1tSeybvMCWeVeTtm/NYqAqP6mRGjLInFZ3Zu+ReVzuu0S6IwbWiHmpSRFQ8TPZTtEQ3O/o4dpdwxy3qp33zxcZ1SPcxIqrMgQQt+0DVZ1kBcpDiwXPEhvBzMRSG6PtofEIlBJj6f+z/S+mR5+xrMkDNwnca1oN90JW/s3PCRuysZmyBbcsIMnPvNaqHpihDMwulraLoRuaXapviCI1/8Tm+fxhnfPo1tyRKhv9wvfVVS/YK9EEVgLMb6qf6mk49OipCHqvqxpZdrt4mHx8LoPLeiAaM5Jlu5yY2D94VWmuSyH/2trjbAIgrYTn0hphSh4eAKkaEpG019r/vt8NXIzKwrvcTXyp287/tDr6YynXtklskoCdihCTcO4/kku/lZZIz1hn2VJ1wlqgPA0I5yuqMCObXw7rJy8owcOYlkjJ37MDl762tnVSjNk28RLdhNLP/ccTUZ27bZYxZ+bDWHoZ3OLTXDt7HNJUEfvy256tTjljiRiJatBSa8p1sNdA0/MmUo36gu0+zoZWUcFhEVABTSWmgYoz0mgPYdetyq4jtPxssS1RE/dgNUUsJVFHLlBXb0QdX6XGTsa8U/Pih 6dlJnTwa wjkKZciW1UzKDly2NUpsALwrnpjiCuIO7OBNm87AAEL4YJWuL2DL51UUR4O1tVV/Vwb6/FtpchNcr+dSOr1jwDRDk21WgDnBzWdKVWA+gIoHdS2sG4PaxOSvc8tRTexmWk/OC/cfGlVn5gIfP31BUPD2rYQRDOF+wyAuMivhNLm46t980PfSzyWyXNGtEGsZZSzkv1/Cwyqx2QcM5KiOuIYLhWyWaWc+HDLq4jqX0Twst4JTmdZgbfGQiEE47Yqq/9C4I+bSjcvoBpEGmtiWYgyUBuT3Z4lsF9JvJwBdkoz+Hiw6XeZCknvSuSdhMj2U13SsN/ZZr3altZLBRTkxiclQphpNuJVBQm+w6Hx3rMEeVzyA= 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: Use _Generic() to create a compatibility layer that type switches on the third argument to either call __kmem_cache_create() or __kmem_cache_create_args(). This can be kept in place until all callers have been ported to struct kmem_cache_args. Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Vlastimil Babka Signed-off-by: Christian Brauner --- include/linux/slab.h | 13 ++++++++++--- mm/slab_common.c | 10 +++++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index aced16a08700..4292d67094c3 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -261,9 +261,10 @@ struct kmem_cache *__kmem_cache_create_args(const char *name, unsigned int object_size, struct kmem_cache_args *args, slab_flags_t flags); -struct kmem_cache *kmem_cache_create(const char *name, unsigned int size, - unsigned int align, slab_flags_t flags, - void (*ctor)(void *)); + +struct kmem_cache *__kmem_cache_create(const char *name, unsigned int size, + unsigned int align, slab_flags_t flags, + void (*ctor)(void *)); struct kmem_cache *kmem_cache_create_usercopy(const char *name, unsigned int size, unsigned int align, slab_flags_t flags, @@ -272,6 +273,12 @@ struct kmem_cache *kmem_cache_create_usercopy(const char *name, struct kmem_cache *kmem_cache_create_rcu(const char *name, unsigned int size, unsigned int freeptr_offset, slab_flags_t flags); + +#define kmem_cache_create(__name, __object_size, __args, ...) \ + _Generic((__args), \ + struct kmem_cache_args *: __kmem_cache_create_args, \ + default: __kmem_cache_create)(__name, __object_size, __args, __VA_ARGS__) + void kmem_cache_destroy(struct kmem_cache *s); int kmem_cache_shrink(struct kmem_cache *s); diff --git a/mm/slab_common.c b/mm/slab_common.c index 19ae3dd6e36f..418459927670 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -383,7 +383,7 @@ kmem_cache_create_usercopy(const char *name, unsigned int size, EXPORT_SYMBOL(kmem_cache_create_usercopy); /** - * kmem_cache_create - Create a cache. + * __kmem_cache_create - Create a cache. * @name: A string which is used in /proc/slabinfo to identify this cache. * @size: The size of objects to be created in this cache. * @align: The required alignment for the objects. @@ -407,9 +407,9 @@ EXPORT_SYMBOL(kmem_cache_create_usercopy); * * Return: a pointer to the cache on success, NULL on failure. */ -struct kmem_cache * -kmem_cache_create(const char *name, unsigned int size, unsigned int align, - slab_flags_t flags, void (*ctor)(void *)) +struct kmem_cache *__kmem_cache_create(const char *name, unsigned int size, + unsigned int align, slab_flags_t flags, + void (*ctor)(void *)) { struct kmem_cache_args kmem_args = { .align = align, @@ -418,7 +418,7 @@ kmem_cache_create(const char *name, unsigned int size, unsigned int align, return __kmem_cache_create_args(name, size, &kmem_args, flags); } -EXPORT_SYMBOL(kmem_cache_create); +EXPORT_SYMBOL(__kmem_cache_create); /** * kmem_cache_create_rcu - Create a SLAB_TYPESAFE_BY_RCU cache.