From patchwork Wed Sep 4 09:44:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13790245 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 58325CD3431 for ; Wed, 4 Sep 2024 09:45:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF8AD6B00A9; Wed, 4 Sep 2024 05:45:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AA9296B00E4; Wed, 4 Sep 2024 05:45:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 96F716B011E; Wed, 4 Sep 2024 05:45:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 79BE96B00A9 for ; Wed, 4 Sep 2024 05:45:09 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 218B7120E01 for ; Wed, 4 Sep 2024 09:45:09 +0000 (UTC) X-FDA: 82526572338.02.8302348 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf30.hostedemail.com (Postfix) with ESMTP id 5456F80018 for ; Wed, 4 Sep 2024 09:45:07 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pVF3VDs0; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf30.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=1725443036; a=rsa-sha256; cv=none; b=xhM2DZjQhmptOdWN4v8TTJ7/kvNG7koP4DOfUzhQi4cZrUnAj9pMukO18FgWyhwFQD1pik iI95JRfNgQCeprBw48l7vooo+RAXrw2cRK48wMxzLDM3r1ZcSttlOMmAjDQ5lP3eOvYVQh mxdwZDeLP81yV9xTywMA25k9Kmc/EhA= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pVF3VDs0; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf30.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=1725443036; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=qdgGJ6cwgEJVO9SKCUaFd/iTWI0ape2PK/7C9NtdbPA=; b=MIlsvzOhUUa+KUVxsedZQIhseV6t2NICrD2vMwb8INqGR+jvXD6YmgsLeYqIF0h+yfTEMZ fNBamfI1xMwhArC5eAU/2n3HushrM1LOG/Gw7JpUsiedU6pdgte21VJqVMANugRnRef7ED OLjYZDED9a0fyt+j19BEmf+9EqWNQA0= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id AFC8C5C497C; Wed, 4 Sep 2024 09:45:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CCDA1C4CEC2; Wed, 4 Sep 2024 09:45:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725443105; bh=0TbYaIlAyW4MAXY6VAEmQDqD02yJBCeFBP+TG2hljGY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pVF3VDs06NfHifXprvecTcWgLyuIjjOZODyuarPgxP4k+4vZj9Xvac302QhHxQeFf SMQSApucUVdM5guUbLcRTK+D6jcI0qdJYKZUalyVBJsy74gWc03qlsaiVmQo4xikpD nW/CL8mNiZIDP3px2IzsFjRlmY9j7nzh6mru0N6b+KWsQK/8QyuBAJDVYtNlqKflUq BE/FQ5IOUMrUUYEqrby/6c/0gqocPGDoQDpSP+IXhm6mVY9M9SCUb/YwGmLUvGaG8G eGoLpj2P045rIPlI+sErjowEbWQ5Ly/NNOE9Inacod2qPzKBy4GeJv4+SCLYhVLeiY mPpxMxhaLJysw== From: Christian Brauner To: Mike Rapoport Cc: Christian Brauner , Vlastimil Babka , Jens Axboe , Jann Horn , Linus Torvalds , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 17/16] slab: make kmem_cache_create_usercopy() static inline Date: Wed, 4 Sep 2024 11:44:12 +0200 Message-ID: <20240904-schieben-hochdekoriert-5808b31c9f3c@brauner> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4667; i=brauner@kernel.org; h=from:subject:message-id; bh=0TbYaIlAyW4MAXY6VAEmQDqD02yJBCeFBP+TG2hljGY=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaTd0BG+rO3986DXU820qgiOTJEnO9YVrd7wYtHurnA9R tmApL2rOkpZGMS4GGTFFFkc2k3C5ZbzVGw2ytSAmcPKBDKEgYtTACby7A4jQ7OAU+ayqjzZul8G QT//LpjBHWRtfqo5/4rC7ZWR83YE+DIybLuTcbRC6kxAqeDRsDk7rxd+XrexYlb/jxWVkq7nf3N nMAMA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Rspamd-Queue-Id: 5456F80018 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: udxs13wh7y4xxmnchq9zej3qeky9gr7q X-HE-Tag: 1725443107-879320 X-H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SbL067O7P5ImaSg/Li3PURzIg2u734IXDHMazwIrqnC7rc9VJCO6aHuuAgsW1W9QHakXZd3T2bRDUj09VU3Daeq3M1A4PH2kYguMu8RNsga6Z8+oUJpKZa4krd2b+9VammqAc+Tb3CIpXiw2z/eJMXFXwBFL8H18aBSgtr0TL1KXUzF5ICRmgDuz4s8/IJwhTbr6wVEokJiFiZLczeliBqP824JiUveO/OsvQrthvm32Eyy+yOLsA== 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: Make kmem_cache_create_usercopy() a static inline function. Signed-off-by: Christian Brauner --- Based on a suggestion by Mike. --- include/linux/slab.h | 49 +++++++++++++++++++++++++++++++++++++++----- mm/slab_common.c | 45 ---------------------------------------- 2 files changed, 44 insertions(+), 50 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index 1176b30cd4b2..e224a1a9bcbc 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -265,11 +265,50 @@ struct kmem_cache *__kmem_cache_create_args(const char *name, 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, - unsigned int useroffset, unsigned int usersize, - void (*ctor)(void *)); + +/** + * kmem_cache_create_usercopy - Create a cache with a region suitable + * for copying to userspace + * @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. + * @flags: SLAB flags + * @useroffset: Usercopy region offset + * @usersize: Usercopy region size + * @ctor: A constructor for the objects. + * + * Cannot be called within a interrupt, but can be interrupted. + * The @ctor is run when new pages are allocated by the cache. + * + * The flags are + * + * %SLAB_POISON - Poison the slab with a known test pattern (a5a5a5a5) + * to catch references to uninitialised memory. + * + * %SLAB_RED_ZONE - Insert `Red` zones around the allocated memory to check + * for buffer overruns. + * + * %SLAB_HWCACHE_ALIGN - Align the objects in this cache to a hardware + * cacheline. This can be beneficial if you're counting cycles as closely + * as davem. + * + * Return: a pointer to the cache on success, NULL on failure. + */ +static inline struct kmem_cache * +kmem_cache_create_usercopy(const char *name, unsigned int size, + unsigned int align, slab_flags_t flags, + unsigned int useroffset, unsigned int usersize, + void (*ctor)(void *)) +{ + struct kmem_cache_args kmem_args = { + .align = align, + .ctor = ctor, + .useroffset = useroffset, + .usersize = usersize, + }; + + return __kmem_cache_create_args(name, size, &kmem_args, flags); +} #define kmem_cache_create(__name, __object_size, __args, ...) \ _Generic((__args), \ diff --git a/mm/slab_common.c b/mm/slab_common.c index 9133b9fafcb1..3477a3918afd 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -337,51 +337,6 @@ struct kmem_cache *__kmem_cache_create_args(const char *name, } EXPORT_SYMBOL(__kmem_cache_create_args); -/** - * kmem_cache_create_usercopy - Create a cache with a region suitable - * for copying to userspace - * @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. - * @flags: SLAB flags - * @useroffset: Usercopy region offset - * @usersize: Usercopy region size - * @ctor: A constructor for the objects. - * - * Cannot be called within a interrupt, but can be interrupted. - * The @ctor is run when new pages are allocated by the cache. - * - * The flags are - * - * %SLAB_POISON - Poison the slab with a known test pattern (a5a5a5a5) - * to catch references to uninitialised memory. - * - * %SLAB_RED_ZONE - Insert `Red` zones around the allocated memory to check - * for buffer overruns. - * - * %SLAB_HWCACHE_ALIGN - Align the objects in this cache to a hardware - * cacheline. This can be beneficial if you're counting cycles as closely - * as davem. - * - * Return: a pointer to the cache on success, NULL on failure. - */ -struct kmem_cache * -kmem_cache_create_usercopy(const char *name, unsigned int size, - unsigned int align, slab_flags_t flags, - unsigned int useroffset, unsigned int usersize, - void (*ctor)(void *)) -{ - struct kmem_cache_args kmem_args = { - .align = align, - .ctor = ctor, - .useroffset = useroffset, - .usersize = usersize, - }; - - return __kmem_cache_create_args(name, size, &kmem_args, flags); -} -EXPORT_SYMBOL(kmem_cache_create_usercopy); - /** * __kmem_cache_create - Create a cache. * @name: A string which is used in /proc/slabinfo to identify this cache.