From patchwork Thu Sep 5 07:56:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13791895 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 AF2A4CD4F5B for ; Thu, 5 Sep 2024 07:58:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E2AF6B02BC; Thu, 5 Sep 2024 03:58:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 394FD6B02BE; Thu, 5 Sep 2024 03:58:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 233006B02BD; Thu, 5 Sep 2024 03:58:06 -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 041FA6B02BB for ; Thu, 5 Sep 2024 03:58:05 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C13081C5591 for ; Thu, 5 Sep 2024 07:58:05 +0000 (UTC) X-FDA: 82529931330.04.E6FE9C4 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf06.hostedemail.com (Postfix) with ESMTP id 134CD180004 for ; Thu, 5 Sep 2024 07:58:03 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=jCEn44ZW; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf06.hostedemail.com: domain of brauner@kernel.org designates 147.75.193.91 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=1725522976; 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=fj5xydkfDIbEb6zo+icpVThUdIzEBlVr7Y2/y2ZvK00=; b=MzRok6IJNHxSoM/kavuRRcdYtkzop8Cv28GyiH/Hu5MYkgUCXPN5thKG8NyxtoeGdhzfU+ nsXt39vlNcxLI+ICwuIfqZfHFMSft1oheTTBVR0fD5kB4adE5KLMcKYSJ/HqK6eHRQu5Ny i4tnAzVSD83DVwUuG9PvpZb9UYTLU/s= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725522976; a=rsa-sha256; cv=none; b=m/s+YlEyBOqODLQssiamRPRxbZNDQY0pXyYc+/R/GgYj6VOBqD1FY4P+fZLPp9lOivNHss Oc1RcQAYIV+9rrdSjUiShJBmd30rG/hmRw33wz3f/W/h4rHY6H/rS11jmnYyUfzAYV5Twb bfVsZD++JvlxWwOQ8jLoeaPI7cNjpOI= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=jCEn44ZW; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf06.hostedemail.com: domain of brauner@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=brauner@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 1DE7BA4434E; Thu, 5 Sep 2024 07:57:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97A91C4CEC7; Thu, 5 Sep 2024 07:57:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725523083; bh=8MPF6aXbdUIaNsM6rCGkaQsu5CsscD0F2Lvkbk763C4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=jCEn44ZWRCSA9HVoaikbAlgBU3BAXgX6znj1B8SQc1aXfEfaCf+J3Q4fxzbhZP5W6 rtBpLbe0X4Ib1EkGzQv0ekZvpN+Vm5TRW1iv0InpFeutCESIk0Oq2Iv3yKZ6p0qIl6 QSVsvTyShitYfBic6Btst0IgZwZnx7Vm99PJpan+xTk8Bls4i+lPzBOAM5x+yiHbh8 jXTpHM8wbwV/yThzpFhtxakWzjPis+aVldz5ERTyEslB6axT1eLYBPs9uVIcuBvkF5 VZtYBHZKRSMFz4439dzA3m9KwZl7r/7o9RkDdIIAKGVCkGGI69dWBHpykvc80J9e98 D7Fe9jhM5aZqg== From: Christian Brauner Date: Thu, 05 Sep 2024 09:56:58 +0200 Subject: [PATCH v4 15/17] slab: make kmem_cache_create_usercopy() static inline MIME-Version: 1.0 Message-Id: <20240905-work-kmem_cache_args-v4-15-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=4607; i=brauner@kernel.org; h=from:subject:message-id; bh=8MPF6aXbdUIaNsM6rCGkaQsu5CsscD0F2Lvkbk763C4=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaTdTPHOYd487fKTZzb1T4RE484+Ejn26RbHH7HqspR89 X8N+T0bOkpZGMS4GGTFFFkc2k3C5ZbzVGw2ytSAmcPKBDKEgYtTACbC2crw39fm9y5vhWt7lc81 rOgSP+6hsrlmx0nlI8KaUU9rYqKlLzL8M8xa73bneNjG24EpL+wmRj02nvFzPZfN95w/rQ8/mJs 9ZAYA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 134CD180004 X-Stat-Signature: d6yws969eyjxjf9fq7uzcdqbgxmyd5x8 X-Rspam-User: X-HE-Tag: 1725523083-594598 X-HE-Meta: U2FsdGVkX1+uUtoierQWOzMt7YOB6ZDGuVBjpZ7/1WovixCWUMymslBIxKvPHcHmhIiGGI3hx125jxNBKpUs7cuCjL9nU1srwHkk/MXT9J2kAiGjCGGNjZBsYcLq8rb2xci69r7wNr7vml71uHPicb4rtqUgdnZqIX7ojBm+6eZQPKNlRllLgUwcSndAgvCaMI13m2Zd5GSJR4eZ1Um1lo9UNMln9TNkuD8wQ0kC7J8hmv78vg2uhcoMCDPh0X6rcaH6k915RC8APqBOIcOYbf63al0v3NEb8WCXA0dsQiR6s29UfAh9oFnHIFtwqU1KgjVyKnRsn18p9p8NB1SkFq6VG+jSg2vGDq58xmiCLjmBWrKCfUghsdFA2uH6f523jOSz+M1sgqtOg6H1OUs+kTGLV/gQNkLSTAGsYt1iUXZX3F24irAkGKNZUstpKEFhWTNtmSrY8e4IT7c/9z7+WIIeDxitpuP2xp7g7plBcapQ6Tha7qVjQWmtBLP9jpa9vI9lpespM8i42bevxknv+SXCR698Ruop4rkhJ0e8gKMGcZlMBTi3PN5RgZERSVj73J5iLc97dA9drE+5RfgYCiDskWnc/XhxzvsHWurP7mxOWWQD5BXxtjqIFBBunFT1bodkO49xLgDMJFywoT3UX7CDEiZpEjtv4QwmqJ1zo/7WnPxpuxZUQGnXu4UJeCBEaM+/foCiXiaVzMKzd7y/+G9dsnmPMivLA7JoI4YaXOalXTmM6kYmqfb15JquZOHPj494Tn4h2x4fCvz9okD+fIFkwCFZ0pbnL1RipUwmqS4dcW4n3FyyrRtQ0z2bTG/teGuLkupmLXFcIBPVqhtnu0jV7Cf0sryECVfmE0E2p7+jVz7FD4hy5x/wPv+XSlQulS1/3ipi+1B8LwBnAGs90BcBOpOAw+0B9o4yfPDaRfy/6keQF0jtOVeXO+rkudyxsZ+NqychRCAEWmQnqK5 zVzCpmAP 1TGaOG2fxPICwFie0V5kpc5qDz2YoFRAMZXHa0XFDMpR8z5awOqPss4ASILS0/h9CvQsCKx2MdLAOy3P5Ip7Dh5kDobgBvbbdZ4IkDKzdfguAMF1ByZJGVCLelMz2YvL87io2bR1QtwjR4xCaT/rA6p8z/OjPyrIK2ujtSqLBkULt5Fk4um78RLXsvTQaD0524j/mSk1ePtHZIjwDlWRJEOk/j6yK03qsf/9OgbM0jDy3cGuFIeq5u5088pu51XMinmn5odwlrVwmJ81MSonRbADuHulubLp+3xuD/MiEUzvHgh/ZCzKvp9Sh0RwqHJorSm23t04NAOBfmFMb6OyHfXwRMQ13xSrOlKMRvi7EKYbkUIs= 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 Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Roman Gushchin --- 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 8246f9b28f43..d744397aa46f 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); +} /* If NULL is passed for @args, use this variant with default arguments. */ static inline struct kmem_cache * 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.