From patchwork Mon Sep 2 15:31: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: 13787430 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 5A646CD13CF for ; Mon, 2 Sep 2024 15:31:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CB9798D00EC; Mon, 2 Sep 2024 11:31:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C6A716B029B; Mon, 2 Sep 2024 11:31:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ABEF38D00EC; Mon, 2 Sep 2024 11:31:27 -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 8E7E16B0297 for ; Mon, 2 Sep 2024 11:31:27 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1F388C02F6 for ; Mon, 2 Sep 2024 15:31:27 +0000 (UTC) X-FDA: 82520187414.18.831D81B Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf20.hostedemail.com (Postfix) with ESMTP id 4FD511C0011 for ; Mon, 2 Sep 2024 15:31:25 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=GkDfTY81; spf=pass (imf20.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=1725291038; 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=EvQEy6kiCow1TB7cL8fZdfuDr28LVReVZuntcDK3BlY=; b=n5UcLfuAZWHaAxB1KQO0u1sgdzd10fQpbdLb/DHPCEx1ChbKtEZJHrDE26TY85QcuK3cJb tR5l+jBbIavzKaxcgkU44/T2uYdCrYbK8OKiiasaMOrwORffvpIw+un0yy9D49c9Ga9uDR 9VSq9br62zcdPrFv4NK+//KyC37XimM= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=GkDfTY81; spf=pass (imf20.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=1725291038; a=rsa-sha256; cv=none; b=wt10SH0pPYEfWz7abCJOGAiqw/LHuh9A+1xjTL7ny1SG/PFu6kjT+o5q4sDHUYeS116kZk U+5tKgmXy6tY+NwX8pn/XpK0zTyEyDpTWOldLF7z77oYvXc5qnIwy9FgdbMPHr2pKajbcE Uznpa8IHt9vkm9rHB3NEiKzlPQasdrY= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 6BC7AA426E7; Mon, 2 Sep 2024 15:31:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6089C4CEC7; Mon, 2 Sep 2024 15:31:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725291084; bh=FHhCTOggZ90P2bzR8bIGtQhfJ1koBe39D/5rVosKgnw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=GkDfTY818QvUJiWNDID1pLShAjMGuCRzHx8UB2Tecndx9t1XTpJrbuPdhkbCr0anT FevEBEO0xiSH0R9L8YiuO8J95NPFpqSb99UiDDk1z7z9jL/c22DSObZB14n5EZOBqo pUxGP/oCVJEepI8jJ9HDazhb6FEefj9qrWM6810lN1GQjQsK6ScRLJTIxB14LXiryN M6WHOz8BLeGraC7E3wDikBYB1HyOgjGbjTQ0ABLzPOE0Duw5/EMzENnsy2b/OWOuSM dhTeXwSY63No/Z8pef8vM07oiKHQWXS+blPA6gOPcRTgncrCla1zzV0Jp8JpuIp1pD oxBT/4EC/kRag== From: Christian Brauner Date: Mon, 02 Sep 2024 17:31:11 +0200 Subject: [PATCH RFC 1/6] slab: introduce kmem_cache_setup() MIME-Version: 1.0 Message-Id: <20240902-work-kmem_cache_args-v1-1-27d05bc05128@kernel.org> References: <20240902-work-kmem_cache_args-v1-0-27d05bc05128@kernel.org> In-Reply-To: <20240902-work-kmem_cache_args-v1-0-27d05bc05128@kernel.org> To: Vlastimil Babka , Jens Axboe , Jann Horn , Linus Torvalds Cc: linux-mm@kvack.org, Christian Brauner X-Mailer: b4 0.15-dev-37811 X-Developer-Signature: v=1; a=openpgp-sha256; l=9454; i=brauner@kernel.org; h=from:subject:message-id; bh=FHhCTOggZ90P2bzR8bIGtQhfJ1koBe39D/5rVosKgnw=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaRdveUhvlL80jlz0YchK2t6xbTSH8c63c7+46FTulxba 4Nr1MumjlIWBjEuBlkxRRaHdpNwueU8FZuNMjVg5rAygQxh4OIUgItYMDI8OPyMa4qcSd/6rwzt tzvf8Jqy6Kz8o1Mxa9azPvFtT6ubGBkO6DWqGixo2ssk8DxsZ8avnqpjXmd0OCv2haieFN555g4 XAA== X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 4FD511C0011 X-Stat-Signature: 1pdmhuzuaigcs68u7dth8i7h1phfm8df X-HE-Tag: 1725291085-382571 X-HE-Meta: U2FsdGVkX19iq+KLHM5QC9qUvx9SHGj7nR/KmBSrjP/1R2DJh0JZftZaDbCKAnhPtbqGLBcJ3M9qLIO0m47rFCokdVWIthgyTXLEwRhj1kZ2nN+Zr5JAxg/iPfwoms81fOSsK8tkX6Ret9HKfRQYsKuhHiBgoGbuNXbg3F2tZzLB58vsSoMbsWXiKVeq4sjRgOkVB8CsmHlIlb6X2uauW7ke1QQ5YGWKIRgM49BaoF0WsaNO+GdwmUf6lBX1elpPpyXFw+rMKctZewNMJe7xrgDcKMg9+zJGxawWtpx2P8acEVtkkUHdZZGbjdszyumeGKV5i3tyhxskwnZoiILMZ2/WmiaR0l+DpXy1tUnc2r2dLtBsiFBbOKDpYY1sCZ6jZrpe12jXa3rVtF4i6OTw/k0c9tg+m5SgGeW+/OA2PNMtFeYqIinDmRd+bBKgAWgrdN/KKseKmpRVaZ89ZN9ySZaQFDEKnFQ7/S2pSfMieQiaw+q07Z2Mx+56lszHfRv9xqo6ZS0U9nsgDgpo3abDMBzW5p4R8CLYUtj4yUXLfYv7I/5krN9et63fGvp5w4ELep0Zcr03gya3JlFaYuUv732YgS8wHaIIswjuqWBOLE8mhFLcQyBIYwg137nj/QmXMaYSPLeoQu1X9QumdBuQSkl0JZV6ZMEaAs7XZ5JCxWCuphU1PgYYDmLYjRCk7Y/AA0RcoV1mGrgyJdImwXiaIe5aB8tI/idTRQSeysF3AFfbAPuuIsZVIBiyE7c909m3tEZdHPhefS0P4e2zYftkUDywbYKe8ohsQn+1yk4LIzkmWly1OiL5KUnPF+EtYvXWgzEnXIbHJRQnB8sDiVgP0BUhtaR38w52P+xC0QaLn96J1IpydffKT2Qtu64wXblqETXyn3ofT5Uas1ubkEksDkCOAR6dgZJK50bu/u5IWAWlIqAwd/bva15Uk4qUSBtRYJCQjOJ4JknW3dWy+61 9vfbw0DR s4yiFKc4mbOYlfIuV8Sqzpx6xYebd4hoO8jgn/qjFeZrF9Vygo5DevJ8ZURM017Ops4lZ4IfITdaFmzTN8qRY4nPkHR70MHn/L67Bb49J+0K9apLm1vlZjvretjoOWiyxjMtq9FNcXz8SfJmbGDKEWXDSyD+6UR455jIyJkT2mlQqa6wrm/qa6T1xRhDjbyypyqD/B2JUEBhc1+GrsubI8UOP0/viLT2DtLY6e2THak4blnx6fBioV1lAA+cs3lk1MwsLyKYkcg6oAqcIDpGXXi2c7sqRAcN7UFze 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: Replace the custom kmem_cache_*() functions with a unified kmem_cache_setup() function that is based on struct kmem_cache_args and will replace kmem_cache_create(), kmem_cache_create_usercopy(), and kmem_cache_create_rcu(). The @name, @object_size, and @flags parameters are passed separately as they are nearly universally used. The rest of the arguments moves into struct kmem_cache_args. A new "use_freeptr_offset" boolean is added as zero is a valid freelist pointer offset. The boolean allows callers to avoid having to do anything special if they don't care about freelist pointer offsets (most callers don't). Signed-off-by: Christian Brauner --- Documentation/core-api/memory-allocation.rst | 10 +-- include/linux/slab.h | 21 ++++++ mm/slab_common.c | 102 +++++++++++++++++---------- 3 files changed, 91 insertions(+), 42 deletions(-) diff --git a/Documentation/core-api/memory-allocation.rst b/Documentation/core-api/memory-allocation.rst index 8b84eb4bdae7..83ae3021c89a 100644 --- a/Documentation/core-api/memory-allocation.rst +++ b/Documentation/core-api/memory-allocation.rst @@ -166,11 +166,11 @@ documentation. Note that `kvmalloc` may return memory that is not physically contiguous. If you need to allocate many identical objects you can use the slab -cache allocator. The cache should be set up with kmem_cache_create() or -kmem_cache_create_usercopy() before it can be used. The second function -should be used if a part of the cache might be copied to the userspace. -After the cache is created kmem_cache_alloc() and its convenience -wrappers can allocate memory from that cache. +cache allocator. The cache should be set up with kmem_cache_setup() +before it can be used. The second function should be used if a part of +the cache might be copied to the userspace. After the cache is created +kmem_cache_alloc() and its convenience wrappers can allocate memory from +that cache. When the allocated memory is no longer needed it must be freed. diff --git a/include/linux/slab.h b/include/linux/slab.h index 5b2da2cf31a8..41135ea03299 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -240,6 +240,27 @@ struct mem_cgroup; */ bool slab_is_available(void); +/** + * @align: The required alignment for the objects. + * @useroffset: Usercopy region offset + * @usersize: Usercopy region size + * @freeptr_offset: Custom offset for the free pointer in RCU caches + * @use_freeptr_offset: Whether a @freeptr_offset is used + * @ctor: A constructor for the objects. + */ +struct kmem_cache_args { + unsigned int align; + unsigned int useroffset; + unsigned int usersize; + unsigned int freeptr_offset; + bool use_freeptr_offset; + void (*ctor)(void *); +}; + +struct kmem_cache *kmem_cache_setup(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 *)); diff --git a/mm/slab_common.c b/mm/slab_common.c index 95db3702f8d6..515ad422cf30 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 = __kmem_cache_create(s, flags); if (err) @@ -248,12 +251,22 @@ static struct kmem_cache *create_cache(const char *name, return ERR_PTR(err); } -static struct kmem_cache * -do_kmem_cache_create_usercopy(const char *name, - unsigned int size, unsigned int freeptr_offset, - unsigned int align, slab_flags_t flags, - unsigned int useroffset, unsigned int usersize, - void (*ctor)(void *)) +/** + * kmem_cache_setup - Create a kmem cache + * @name: A string which is used in /proc/slabinfo to identify this cache. + * @object_size: The size of objects to be created in this cache. + * @args: Arguments for the cache creation (see struct kmem_cache_args). + * + * Cannot be called within a interrupt, but can be interrupted. + * The @ctor is run when new pages are allocated by the cache. + * + * See %SLAB_* flags for an explanation of individual @flags. + * + * Return: a pointer to the cache on success, NULL on failure. + */ +struct kmem_cache *kmem_cache_setup(const char *name, unsigned int object_size, + struct kmem_cache_args *args, + slab_flags_t flags) { struct kmem_cache *s = NULL; const char *cache_name; @@ -275,7 +288,7 @@ do_kmem_cache_create_usercopy(const char *name, mutex_lock(&slab_mutex); - err = kmem_cache_sanity_check(name, size); + err = kmem_cache_sanity_check(name, object_size); if (err) { goto out_unlock; } @@ -296,12 +309,14 @@ do_kmem_cache_create_usercopy(const char *name, /* Fail closed on bad usersize of useroffset values. */ if (!IS_ENABLED(CONFIG_HARDENED_USERCOPY) || - WARN_ON(!usersize && useroffset) || - WARN_ON(size < usersize || size - usersize < useroffset)) - usersize = useroffset = 0; - - if (!usersize) - s = __kmem_cache_alias(name, size, align, flags, ctor); + WARN_ON(!args->usersize && args->useroffset) || + WARN_ON(object_size < args->usersize || + object_size - args->usersize < args->useroffset)) + args->usersize = args->useroffset = 0; + + if (!args->usersize) + s = __kmem_cache_alias(name, object_size, args->align, flags, + args->ctor); if (s) goto out_unlock; @@ -311,9 +326,8 @@ do_kmem_cache_create_usercopy(const char *name, goto out_unlock; } - s = create_cache(cache_name, size, freeptr_offset, - calculate_alignment(flags, align, size), - flags, useroffset, usersize, 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); @@ -335,6 +349,7 @@ do_kmem_cache_create_usercopy(const char *name, } return s; } +EXPORT_SYMBOL(kmem_cache_setup); /** * kmem_cache_create_usercopy - Create a cache with a region suitable @@ -370,8 +385,14 @@ kmem_cache_create_usercopy(const char *name, unsigned int size, unsigned int useroffset, unsigned int usersize, void (*ctor)(void *)) { - return do_kmem_cache_create_usercopy(name, size, UINT_MAX, align, flags, - useroffset, usersize, ctor); + return kmem_cache_setup(name, size, + &(struct kmem_cache_args){ + .align = align, + .ctor = ctor, + .useroffset = useroffset, + .usersize = usersize, + }, + flags); } EXPORT_SYMBOL(kmem_cache_create_usercopy); @@ -404,8 +425,12 @@ struct kmem_cache * kmem_cache_create(const char *name, unsigned int size, unsigned int align, slab_flags_t flags, void (*ctor)(void *)) { - return do_kmem_cache_create_usercopy(name, size, UINT_MAX, align, flags, - 0, 0, ctor); + return kmem_cache_setup(name, size, + &(struct kmem_cache_args){ + .align = align, + .ctor = ctor, + }, + flags); } EXPORT_SYMBOL(kmem_cache_create); @@ -442,9 +467,12 @@ struct kmem_cache *kmem_cache_create_rcu(const char *name, unsigned int size, unsigned int freeptr_offset, slab_flags_t flags) { - return do_kmem_cache_create_usercopy(name, size, freeptr_offset, 0, - flags | SLAB_TYPESAFE_BY_RCU, 0, 0, - NULL); + return kmem_cache_setup(name, size, + &(struct kmem_cache_args){ + .freeptr_offset = freeptr_offset, + .use_freeptr_offset = true, + }, + flags | SLAB_TYPESAFE_BY_RCU); } EXPORT_SYMBOL(kmem_cache_create_rcu); From patchwork Mon Sep 2 15:31: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: 13787431 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 69AA9CA0ED3 for ; Mon, 2 Sep 2024 15:31:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A6BC6B02A2; Mon, 2 Sep 2024 11:31:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 458EC8D00EE; Mon, 2 Sep 2024 11:31:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 280188D00ED; Mon, 2 Sep 2024 11:31:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 08F106B02A2 for ; Mon, 2 Sep 2024 11:31:29 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B2EC5AA0CB for ; Mon, 2 Sep 2024 15:31:28 +0000 (UTC) X-FDA: 82520187456.28.13FE92E Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf11.hostedemail.com (Postfix) with ESMTP id 05BE540014 for ; Mon, 2 Sep 2024 15:31:26 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZKNohXwN; spf=pass (imf11.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=1725290993; 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=egUh6GR5wZg3MtEyM/sPaqQeCgeGapkObqZI9iCMGNc=; b=Z2Cg0jeBRNPAISD1tu2Fv6QTnkbL0tzmRnQRb4ABejpRw9OGOR5LZmyLWjos6PGTz1WOK5 IJsDdvJoqvpQe4ky4trqes6SdkfuKOq78ythYO2akoTgsIuJtYpNU6yCDS92SMJl+eSrIC Ida8db036W45txrW95ruv+xM8T/t5fU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725290993; a=rsa-sha256; cv=none; b=J7fHf9RZxeuuX0kB3Xa6u7Xt5pNuySRJS2dsVbTeFnccdgeunPZ08CQ3ZN9NketPnXh9pX dkHgwNkNf+MkA1KnkqthLOz/RyrsBXWiE9QgGXIpKhS/awo87EtHrs++/UhkWVIROeaCGE X4kEhoi1ah4Kv2vixoiepMOVi0emjCU= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZKNohXwN; spf=pass (imf11.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 40101A426E8; Mon, 2 Sep 2024 15:31:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0877C4CECC; Mon, 2 Sep 2024 15:31:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725291086; bh=HEPcw9oVQsLcGOdntDQpdEMJb74lNJy6nBGCOOTirx0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ZKNohXwNn1ekDhwosaSFu7EriBUtgV9TVlnh9wsrXJ4N5z34ajsbbm18WbvM1LD3p 61neHkswomPcxqIiUCO6IkbRLDOutv0YxBZFSRdbltz3lBB8hduP/sQt1I2w/07FXB WPTNgFCqJqTC5p9XusQjvhRQgtmn7HQEcwcstDcq3wzuCdzodkgzeJg9Uz9CqkWCWU NlKUmYrbCDhuUVEAF2shxTAyehV7qgfVvRo5KdgpXYMDqj0yFLpQB2jDCfuSHfOSsb fA0darp5MKUwANPmFXlGyowyr963SCvs3SFp6SKLvxQQjN5ePhDsUOXSmsuGMocoK6 86t8xu3w6gn4g== From: Christian Brauner Date: Mon, 02 Sep 2024 17:31:12 +0200 Subject: [PATCH RFC 2/6] slab: port KMEM_CACHE() to kmem_cache_setup() MIME-Version: 1.0 Message-Id: <20240902-work-kmem_cache_args-v1-2-27d05bc05128@kernel.org> References: <20240902-work-kmem_cache_args-v1-0-27d05bc05128@kernel.org> In-Reply-To: <20240902-work-kmem_cache_args-v1-0-27d05bc05128@kernel.org> To: Vlastimil Babka , Jens Axboe , Jann Horn , Linus Torvalds Cc: linux-mm@kvack.org, Christian Brauner X-Mailer: b4 0.15-dev-37811 X-Developer-Signature: v=1; a=openpgp-sha256; l=1199; i=brauner@kernel.org; h=from:subject:message-id; bh=HEPcw9oVQsLcGOdntDQpdEMJb74lNJy6nBGCOOTirx0=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaRdveXR08P3fefEOb+mzQv3/HHzY5HJsvMT66Zv13n5m VN588rZ7zpKWRjEuBhkxRRZHNpNwuWW81RsNsrUgJnDygQyhIGLUwAm8syCkaEjodNASmnftBg+ RS1ng6KtYpWyv9SkeuO3PPjUY5i2dyojw0aOLkVDm65X/GuVuKtbYizNWqqW3Dn2yS/hJ+vSp9t 9WAA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 05BE540014 X-Stat-Signature: 8xf5cxfrn4kdh1y774oncyfeu11ognuo X-HE-Tag: 1725291086-448342 X-HE-Meta: U2FsdGVkX19AkwSKUjdxozkQq0vwAzNrdYemX5LCVdeqhXeqjnH/6ldTNrAb8qIqiR0vU/BOQhdmwGhFlPn8AmwJrsydxyAA4kKb3sXkQBNLZI2ByVmeN/hAgk4+r8mVcQYDt1v1T/IvbOmfqlfHoVp8C1oxCrYRpUZn+1k42JawdzfSjfZxoXgQ/WHHFBIIV43LQshJl00UxK3RPu7ZOmMlEBkamI9pI4Oyu9/QXujJ8enx4ppkGAWT6cUYdQN8dp6bXqKmMuebymyqNmEikOITsZeld3PB9n/OwHLJXjPf88XzeS1ohihnu5QN3K32HdjNlNtv7WXSJRZQUytkOnsdCuoTfra8+l8B2bCxuSvztbKrfcjoWa0e+N1QOZ2fwYK4Fj9EQ3db2tkcRXSqEA7S9xmO9Hy/m8hx46eys/QMcOWL7rGI+5sB5eK4Ep5q2sm8SOAz/at9vz/bKGvjtSVeLAO9azwhW0mNcFTNkdmPXIYwzZchfkku3nMwG6dCzGBwLWky2wwHasBGaVJKMklsyPdmu18mSTqKyJ8O6IRjw2wRxUqo4pHGv1J6+tN3SO0RorK5zgzbtuqT9lhV2QzC9jPW9xE/E8OFTgCRJFndYDzao3j0ziO7wSYJhUKIuJySTNfAn9KfUIOv5Ok7ywOkURk9sOsPenz1rZh23R2ZLH1YqCGBkPufdV+gfYq5Jf9wOAqiLi4/W9aD9uXJzBxhy1xFt95vBbBzHBSmJOgYUqqAzbcYaQ+pZRKHp2cEGiOo+Vkw8ExUceTcugyH4n9CJyam/1+d12xQZGhG+gn3Hgb/YbZ9Ea1Q1Dtmy1vL1ROm+Q3LK2mJ7oXo0c93xLPJRz/VYXlkyOeuhc26ZQvE4Yfs1e6zqzVMjHEZWgwsBRzzf/TTV9Lkoi0bFRRceDaM8I6iOKTXhn7DfIyLXsDwKEZNYPZ0sBfTT3c33uj+JDuE/9L5kUrLwHr0zg3 1vhi6IiT IgFjA9eiDrSiTzFUcEDh5Yt4vKEUNrMGFI67LYf8DBWrX2z6Bmgj0kIGsjWJBGN1+btZuAqzDmQ5eGWo+AfRueXmICweJADVzCsOf3F90VyfVW2aayi94+MytxZQGHjknoKhRuMEgY9Iodxrb77pmK0K0C839OSMHorneECc/M0+6Xv93KoH3i2F8ye7XOtgI95AsID66cPhDqrmU0ob0p+HdTC8H89+t8dAZatgJw9pK83Oxx1Oogvq3E+xJ32CR0KhSeBK6j1mK0PEBzw9mIq75FSSkoJPFXSPx 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() use the new kmem_cache_setup() helper. Signed-off-by: Christian Brauner --- include/linux/slab.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index 41135ea03299..79f4799b7083 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -283,9 +283,13 @@ int kmem_cache_shrink(struct kmem_cache *s); * f.e. add ____cacheline_aligned_in_smp to the struct declaration * then the objects will be properly aligned in SMP configurations. */ -#define KMEM_CACHE(__struct, __flags) \ - kmem_cache_create(#__struct, sizeof(struct __struct), \ - __alignof__(struct __struct), (__flags), NULL) +#define KMEM_CACHE(__struct, __flags) \ + kmem_cache_setup(#__struct, sizeof(struct __struct), \ + &(struct kmem_cache_args){ \ + .align = __alignof__(struct __struct), \ + .ctor = NULL, \ + }, \ + (__flags)) /* * To whitelist a single field for copying to/from usercopy, use this From patchwork Mon Sep 2 15:31:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13787432 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 383F0CA0ED3 for ; Mon, 2 Sep 2024 15:31:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3942A8D00ED; Mon, 2 Sep 2024 11:31:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 31B506B02A5; Mon, 2 Sep 2024 11:31:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 195DB8D00ED; Mon, 2 Sep 2024 11:31:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id EF55B6B02A4 for ; Mon, 2 Sep 2024 11:31:30 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9E9C8160283 for ; Mon, 2 Sep 2024 15:31:30 +0000 (UTC) X-FDA: 82520187540.09.5BD9030 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf24.hostedemail.com (Postfix) with ESMTP id C7EC818001E for ; Mon, 2 Sep 2024 15:31:28 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=EPNxNTKu; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf24.hostedemail.com: domain of brauner@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=brauner@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725291019; a=rsa-sha256; cv=none; b=ZFomvAWmP3OeUZiALx5fgr/EEV7mWSnoa/JIN6nU/3c7w4AHffpc+8JNdQBu579qBhvVDE 167ZjrLzAEOsyuTZ9DLQtHbd+azdWBbZ1SxJC0uy+EfxGE2SViiKX4Dqo4C4E427z/5bVt oa++c2jdjzAnBG0ggbcb0RqF2/7gIys= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=EPNxNTKu; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf24.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=1725291019; 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=90SHcvMsbdNnqjgumEcJgbzVisqYtJ/leNjYKGgh34U=; b=q+eN+6wv4X6t/8FKMagS0RBS+ugY+bD5yT+sbYtrFzqbezcUhTzROAr1DP2+YtNNRMF7hG lkpNvab3cZ/wVtwL03dUu87Hjq9T//CEY1AHBtYAlur/ig2t+aeZA4jJvUWqlxYtqTUsQZ 4jIBz4NrQlSmkXMngSIpxA05mRfHxfs= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 0DDFAA426E4; Mon, 2 Sep 2024 15:31:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 773CFC4CEC4; Mon, 2 Sep 2024 15:31:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725291087; bh=Zpt9lSArTGXLvcTSsZDpq8nm6fr+snVIvMpKU7zrw4w=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=EPNxNTKumdFSDoKqTWxRdfaOUES2A8xnZKBBUpnCFEq2D3TvtkhDry6yMwS/WA3S6 u7vgRoF17UFn59ueMrkVKC2hbLv5x0o4al0rPCQPG2Crg40fJo1KMblb/DOmcddNKJ kIH1i+9M7/CjJn9pXEDX+lcxIBKRrboj/Dcq7hyNOf1a3H6a7K+hmt5EO1L4OhtDmg y9x8S5xlsV/Uw4AlIOM43V7QsGDVHeOgj3ABMwJOG9vQ6xQ253jNAkxg+Gtg/OVkiV Aw1IVNjZsE/UhFLvEUWIStEWIp+UhOExEwOkmSq0iZZJi6yZJAcrbiDaKagJHqtSwF Mmq0OaUGtCQ6w== From: Christian Brauner Date: Mon, 02 Sep 2024 17:31:13 +0200 Subject: [PATCH RFC 3/6] slab: port KMEM_CACHE_USERCOPY() to kmem_cache_setup() MIME-Version: 1.0 Message-Id: <20240902-work-kmem_cache_args-v1-3-27d05bc05128@kernel.org> References: <20240902-work-kmem_cache_args-v1-0-27d05bc05128@kernel.org> In-Reply-To: <20240902-work-kmem_cache_args-v1-0-27d05bc05128@kernel.org> To: Vlastimil Babka , Jens Axboe , Jann Horn , Linus Torvalds Cc: linux-mm@kvack.org, Christian Brauner X-Mailer: b4 0.15-dev-37811 X-Developer-Signature: v=1; a=openpgp-sha256; l=2113; i=brauner@kernel.org; h=from:subject:message-id; bh=Zpt9lSArTGXLvcTSsZDpq8nm6fr+snVIvMpKU7zrw4w=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaRdveWx+ZC/lp9vyxPvqR9/pvwNvvLLrPtT5TUu+YrVC 7JfzRHY3lHKwiDGxSArpsji0G4SLrecp2KzUaYGzBxWJpAhDFycAjARkceMDAefiptt6W80T/jb G8Y/qYHnXvzz7NJPVcqLg4/ddT20RJrhD/fSr9oMT43nMQpyvKt7l8wYFsl9RUbS+8u8rH2Mv/m lmAE= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Rspamd-Queue-Id: C7EC818001E X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 9poctzbdq8z3a4yfmrzrct38i5ag1yj8 X-HE-Tag: 1725291088-809289 X-HE-Meta: U2FsdGVkX19BBxG9RefNv6xyGXgqoYXLZIKGJVntjfWquzQ5VEGonKH9aIP/ck67iIV/K2NqvGQRtUbmtRIqPvN4JzIswNtTl0YDDoB0e3XW/vRwysDeP32zOj1u3NTg3DRnyye0vwqVxXKU2x9rm7HjoI6X30zpydtBaj0Yo9zCY333iV4aECBsqSSo0mbsAnHF4DgY8hDaeZvF35TO6hWy14A9aSvCiVgb0Q/+bBj+WRw47HW1bS1Uu2Ekp2vvqUffGYPXoTAiyHINL+/5VyuZTGJFwMQ32JyjKvpKJa+mFw/Ye0Dw3NRc5OrrBbLz9Yamh1II/UDNihEE1Ac4UiP7t9IIG35CVvTYJaV32/Kmj4G9N9Twdyw6PtXFEFW149wF10sjMvkqflcBrG6dWXgjA1EOEUjBZFTCEL2pBBvm16EzZZfRbZgt+LIVbl6mfb+Cr1No8Sz3/sumNVIg5ss8C9AavAAYTc+WBH8E/gkb3cLdNdAa+S4qmwMhalTq7rhqWruISgiNsgqO0Ls1Ru7QeMDf9+8yaXdVzz0qOWqgQaSIR5+ikiqHMWLiMR7D23YOI/xRcguIgvh80ZpO4UxQuemynZO+juxEZLD41EAUHyPq4g+DD9qSqIaNysAp8+Hj2HlDR+X74q5+V96UBb2qkj5XEN+q2nVd/KrOPtEAYGWcXBcVm19iYPeaRR/AqS/W74rSEnyiA8ZGr28P/i9wlR50sUKqI7F9PY12Co4Lav8mRisgT5v3WOE23mvGBZnLxAjPdrUGCwekxwOMbl0sqhVrCqxMO/xLId+NgA5odCu1Y9gdXtlQ8NpjRryMi+HrAw53FQZ3giwX6eqn14QYHr6fjqfk1waeZv24e13djjuiAdMgkVoPdCuh5cXfY8eWHS4oubWNBHc9ngAVdHr7z4UzVRxkKS7s8m7MSoEc5NbjzKbLH/Qz9ya4Czh4Qp1Ay0u9lRsZp8BLB0w g92Go4qs S+zvlhQVy4Y9KEwKFsvANlw0+yc5Gxbzwkp5SA3E7x6bVw8oKvheogwe9+wK6r0E7x97Jb8k704JS4kikzFTdJGpjNpuqC7VRuJ9PuZ55R4Go+DiGZ2amv/9Pyy6oxuIGpmwGd6HL+p33UPgksiogRICy1yCE3VVVf2OsfXKv0ulPY1L1aLQ3hcDnAmnMbnBnXjFWOpjKTgBUjHNc2B4QjAihZhIkqj1AXbHR/IH5Kvm2+Ve4naHwS3Xa9luWr+3we9CpPCHQ9of4HpjW0lTqpxmo9kZ2+lyhautgcw5T/AozoQY= 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_USERCOPY() use kmem_cache_setup(). Signed-off-by: Christian Brauner --- include/linux/slab.h | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index 79f4799b7083..52928474e6a1 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -283,24 +283,29 @@ int kmem_cache_shrink(struct kmem_cache *s); * f.e. add ____cacheline_aligned_in_smp to the struct declaration * then the objects will be properly aligned in SMP configurations. */ -#define KMEM_CACHE(__struct, __flags) \ - kmem_cache_setup(#__struct, sizeof(struct __struct), \ - &(struct kmem_cache_args){ \ - .align = __alignof__(struct __struct), \ - .ctor = NULL, \ - }, \ +#define KMEM_CACHE(__struct, __flags) \ + kmem_cache_setup(#__struct, \ + sizeof(struct __struct), \ + &(struct kmem_cache_args) { \ + .align = __alignof__(struct __struct), \ + .ctor = NULL, \ + }, \ (__flags)) /* * To whitelist a single field for copying to/from usercopy, use this * macro instead for KMEM_CACHE() above. */ -#define KMEM_CACHE_USERCOPY(__struct, __flags, __field) \ - kmem_cache_create_usercopy(#__struct, \ - sizeof(struct __struct), \ - __alignof__(struct __struct), (__flags), \ - offsetof(struct __struct, __field), \ - sizeof_field(struct __struct, __field), NULL) +#define KMEM_CACHE_USERCOPY(__struct, __flags, __field) \ + kmem_cache_setup(#__struct, \ + sizeof(struct __struct), \ + &(struct kmem_cache_args) { \ + .align = __alignof__(struct __struct), \ + .useroffset = offsetof(struct __struct, __field), \ + .usersize = sizeof_field(struct __struct, __field), \ + .ctor = NULL, \ + }, \ + (__flags)) /* * Common kmalloc functions provided by all allocators From patchwork Mon Sep 2 15:31:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13787433 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 1D84BCA0ED3 for ; Mon, 2 Sep 2024 15:31:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB84D8D00EE; Mon, 2 Sep 2024 11:31:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E3E936B02A5; Mon, 2 Sep 2024 11:31:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C91F58D00EE; Mon, 2 Sep 2024 11:31:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A259A6B02A4 for ; Mon, 2 Sep 2024 11:31:32 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 637E341D80 for ; Mon, 2 Sep 2024 15:31:32 +0000 (UTC) X-FDA: 82520187624.02.25C52F1 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf24.hostedemail.com (Postfix) with ESMTP id A842F18001D for ; Mon, 2 Sep 2024 15:31:30 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="E/0Uh88Q"; spf=pass (imf24.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=1725290997; 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=5FYPr4aCNzWDRXbqqPdO9GN4olE+iA/3H9/0livHsY4=; b=u31tucXW0eLbp9oWTPdAeZnSSwE1QolVeu8vdM3s3/7ExYRd6nX4u3VRNMBAQ34rWdoCXk XUU/YJzVTXM4kDDKJV+GPq17M0FRsJEdQn8HUjAW4p6SbV8cXxSFQmI2NC+xBYoD9K73gS ehrEZY8NFglvNKu5tnms9hkznDtZxc8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725290997; a=rsa-sha256; cv=none; b=fLLj6dCT6huNccsKHCp4RhKyg/CljYQ1o4knL742EshT2v7Y2czTxe6R/f6a6BaskUqt9z aJgWiDHye6m2yABnSNVpUkgX1OltDRFmA9cq/v7Gz/bbDTds5gxLZL0Lev8FpsVS53iqmm Y0COtn/H1ozujIg4wZvTpxS4qOlpCyE= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="E/0Uh88Q"; spf=pass (imf24.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 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 7F9E25C5887; Mon, 2 Sep 2024 15:31:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 484DBC4CECB; Mon, 2 Sep 2024 15:31:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725291089; bh=732txxnzLhoaBjRvRLxjSsmpCvQWD20I2MzPm2IaCbc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=E/0Uh88Qt6/BNLSu/A9HFA+HxI4Erhpv0jFPPMZkLgEZwccyV4J740jIjPb7CYm4f kIP+N0fx9lEg5jBmiotFoiLjnTImW8tEyKRI8SB9Bn1teW+8MZxhr44rZ+KnMB6qx6 +aGxZEcQYUjY1LPBptAKC1CDCsYNe7adGxyREFseQVaaIH/1K4ozvjAoBQZ5ehbjmm zISmukooxmX4sleHVzfNm0dEFUo+1kwDK45rOiHPKF1Tq5FKjdR1hrlUj4YGMbDh17 fwmk9DZGXKa+mzWCb+Vliaq6ZKBZsQz4IUxW+z46Fqd+RMIjqLzYsP8GsIyyH+RSTU 3IuRIUsZfNtqA== From: Christian Brauner Date: Mon, 02 Sep 2024 17:31:14 +0200 Subject: [PATCH RFC 4/6] file: port to kmem_cache_setup() MIME-Version: 1.0 Message-Id: <20240902-work-kmem_cache_args-v1-4-27d05bc05128@kernel.org> References: <20240902-work-kmem_cache_args-v1-0-27d05bc05128@kernel.org> In-Reply-To: <20240902-work-kmem_cache_args-v1-0-27d05bc05128@kernel.org> To: Vlastimil Babka , Jens Axboe , Jann Horn , Linus Torvalds Cc: linux-mm@kvack.org, Christian Brauner X-Mailer: b4 0.15-dev-37811 X-Developer-Signature: v=1; a=openpgp-sha256; l=1000; i=brauner@kernel.org; h=from:subject:message-id; bh=732txxnzLhoaBjRvRLxjSsmpCvQWD20I2MzPm2IaCbc=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaRdveXBJNfCcHMTl+vumzWWegtmbfi/aULHG71Z3x8/D NduXKS/uqOUhUGMi0FWTJHFod0kXG45T8Vmo0wNmDmsTCBDGLg4BWAiK74w/M/x4L2eYLb41Jeb 7ncWCEt8ejApul35vM+umGtezBoyCj8Z/td9/ydozfdu5jQnhefXvNfGLNHUWrHmQHq89oKNlx/ UTWMAAA== X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: A842F18001D X-Stat-Signature: 359k95jsrghjzu4cnjkq9n5f9nbp914m X-HE-Tag: 1725291090-365555 X-HE-Meta: U2FsdGVkX1+LALOxhIHl/5hUEPX7LOXngXRkS1MrKwyyt8hofwn6hFGN1NWsvz0WK7xvws0NkGJQdYd6DbPAWI7ddqyzrKECjTrsMq87Gy/Ortz17eCHBOqpl7dMX3P5W+lTFHWItjPrNgEL1dO2vY1vsAAEzYHqhUtepZwXrPZqrNLk2R4dWhobfwyA9BjAa0WjKCUJ3XBYTXYJKb4Iva8Wnt312SUK5pA073l7iZKhg/6zy6KalIrPn+aOGzZu2B1v6AK85Ouq3+ryOAqSixT92Ev+96QdPT/otP5kJLPhbdbOPzg0f+T3FdgCBOLXaYIp2uWc3ka+pvbOFLuRbDHwIhbzeqxcPmuXm8qyvwRvz4O/cP5dlqShnS4uXYUA5Bs1SiDEjVbuQxC+m6UpiZN1J9kFLjULXdrnkO2IIVZgTEWs/odgLEAG5zsUQD8IBKW6h9XBXWZtZfzOfHGBUtEy4AzYmgQRSHxvKWQfEOGUJYjoRViRWV8QI8o6QsPFRLXjdMP+BBHo8TyX9gC2eOmd+Sn4Taq4m90fUGsc5dzbAJxqdb5JEME4nTIVTRPcKCZc/YKiksb+742LnC61512ExB6omlGQrYqs50EydWJZCg9ZkYJFoM+kqtvuQ3O8ivuMDlDTYUawb0ObrcbaUpFSulzUDlN5KhHgu5rNlg6jaw4MzDMhwI6wA2/ACsFsUx3wJ6IoBVRbGV/F1rBxJpNyUEgx6aEk70iKr52I+dypsYGWD0tuy3L/IbNVX/6h8Av2TlxBKE5XYeah4Y/uZv2ec/NHIc5VHgbplavq8aNu5kDncJBioSG80CpyGKH213hJDITmu23CHlkoc3YV6xVEuGy/DkvZbtU8zhi5EsKExIX3+Yext1EyR/8ZlGGGT21BdHQ0/Fg9cpeDGXm1pc0QKmT9xho96WZLaV+AhQwQA6Yz+2WWuiAC4k9IAou9S9h5qjZ47wk0z3OTx9v nameB3Ur O0z9kLmvXdOP9B21XfifSOVr9JJH95zPvQMUBKRqxMAtzyQH8FPRhVU5HXe/hyhPn+Edz2bmeR4xdF6AroCQRFjrBIszNh4L99FKNV7gUDr64Csr9WbHiG9ILs1c5c+HoXw9bWvHMKRr6czZCCm8EHC4Asuw63iI+6DnS4+Ox2e/301wm0XQzB2jzyVMKMxMn3FRBGLcyrJ9LzE5dPPblKdZ+A6Ie8sXreBkbhYiSz9CNaNREEX2TpkoYXWyN0GGaNtOn0nGmX1EjiQUlVAKSlUIy/eINXE4qik+g 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: Replace the custom kmem_cache_create_rcu() method with a regular call to the new kmem_cache_setup() function. Signed-off-by: Christian Brauner --- fs/file_table.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/fs/file_table.c b/fs/file_table.c index 3ef558f27a1c..c20066b3f677 100644 --- a/fs/file_table.c +++ b/fs/file_table.c @@ -511,9 +511,15 @@ EXPORT_SYMBOL(__fput_sync); void __init files_init(void) { - filp_cachep = kmem_cache_create_rcu("filp", sizeof(struct file), - offsetof(struct file, f_freeptr), - SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT); + filp_cachep = kmem_cache_setup("filp", sizeof(struct file), + &(struct kmem_cache_args) { + .use_freeptr_offset = true, + .freeptr_offset = offsetof(struct file, f_freeptr), + }, + SLAB_HWCACHE_ALIGN | + SLAB_PANIC | + SLAB_ACCOUNT | + SLAB_TYPESAFE_BY_RCU); percpu_counter_init(&nr_files, 0, GFP_KERNEL); } From patchwork Mon Sep 2 15:31:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13787434 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 0A4EFCA0ED3 for ; Mon, 2 Sep 2024 15:31:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0FAA18D00F0; Mon, 2 Sep 2024 11:31:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0AA518D00EF; Mon, 2 Sep 2024 11:31:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF0118D00F0; Mon, 2 Sep 2024 11:31:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id BEF1D8D00EF for ; Mon, 2 Sep 2024 11:31:34 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 700E9120113 for ; Mon, 2 Sep 2024 15:31:34 +0000 (UTC) X-FDA: 82520187708.22.4892F4C Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf15.hostedemail.com (Postfix) with ESMTP id 964D8A002A for ; Mon, 2 Sep 2024 15:31:32 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=IOE5Q5IZ; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf15.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=1725291023; a=rsa-sha256; cv=none; b=m0UaMaMPq6Nz3K5/tTB6lavMYks5CLe+p+OIW402lIvgeO74l3Vuu0Quaimbs3naItfipt +KBcFZAhUdjSJlLzvCsu+hoLsS5WlDPyHKVtoXfvJkoIWJVGAwJLYTmg4V0EN5zMDgk2JB esYkAxzlUxKVWGx2Hhi7BlwMxhfBYco= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=IOE5Q5IZ; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf15.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=1725291023; 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=3QJOD5yhOQMr3yYbiCl1BKPaQmgN0Uy6uWL9wx2gqZk=; b=8bWwqQz3S4eTVwnTAD9XL/8vFeA84RqDgZm3AB+b2pUjTodx40+Nt5AXMP3YCYsYYg89oJ kJfmbw+L5kvO9xCyMyTfH8BrmYgmBH2fukNLn0uVcgWX0wWD51yHD1NMNDcsU78aIhiYCM UQfC8l/30mj8nw+pUedyv5G+qCu/GCU= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 588485C5886; Mon, 2 Sep 2024 15:31:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0841CC4CEC8; Mon, 2 Sep 2024 15:31:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725291091; bh=9zu2IbGpv71HoVCdgColGdhMpTajDXjwvs1F+AN7ueA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=IOE5Q5IZY+FNytF5Ytes7FjALMN9owAMe2PzG8Q+gotcCbynaYu4Ein1twqiu7WEG CaoBlN7jrbD4KhBCpZtHMFf3KB3l33WpIY2ADs+wuIhkfJ1yIbJlIjuKEXm+prxnDL JalHlQYoG8fFapzM82qLGTdFCK7xhkR7s5kvEhkCwkaCZPCzQMWh//bY1k+y3H7UDj sPxmWIlbCbLrekonQaVhB15jk3vXTiooCPIRGNjC6n/O6gUfwLE1y3l/FChQxcDLrZ NbVOhfc6/+5mbMS3P8kKI/KSfFPnJP8lCOuPGr7o07nZUkzFCjqLUjMWcc9zbrCm3s jXZYmhcJfXgSg== From: Christian Brauner Date: Mon, 02 Sep 2024 17:31:15 +0200 Subject: [PATCH RFC 5/6] slab: remove kmem_cache_create_rcu() MIME-Version: 1.0 Message-Id: <20240902-work-kmem_cache_args-v1-5-27d05bc05128@kernel.org> References: <20240902-work-kmem_cache_args-v1-0-27d05bc05128@kernel.org> In-Reply-To: <20240902-work-kmem_cache_args-v1-0-27d05bc05128@kernel.org> To: Vlastimil Babka , Jens Axboe , Jann Horn , Linus Torvalds Cc: linux-mm@kvack.org, Christian Brauner X-Mailer: b4 0.15-dev-37811 X-Developer-Signature: v=1; a=openpgp-sha256; l=2955; i=brauner@kernel.org; h=from:subject:message-id; bh=9zu2IbGpv71HoVCdgColGdhMpTajDXjwvs1F+AN7ueA=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaRdveWxb7e6YOeh5xHvX9eZh9/ZH3jcY5tSaMWpdv+nk wJmxbj3dpSyMIhxMciKKbI4tJuEyy3nqdhslKkBM4eVCWQIAxenAEwkSZ2RoVH9uOE0Z/l/s76I TfbNYju/XlW8LflT4/zSR7EWR+38njIyLPldE5hl1n93jr7zjsTD19y9I687StjMLGgs++Cl9uA QCwA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Rspamd-Queue-Id: 964D8A002A X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 4bdgfiisoxb45rdnc8tgam3wz6najznx X-HE-Tag: 1725291092-755832 X-HE-Meta: U2FsdGVkX1/3j8Ewql67W/yMcyYFJN0V/78DbK7eyy5pw9cyA2fBrAYB/2e5DyYq8b4AN3LTL/TY19VvkSXbu2ex+C1eHVCjMMQGfpYG0n/2ZcP4S09MUhjyi3MlWpZUAJUYtZe/GhT1UEXHvqj8vr1pMmIhtDVqYhxiRGf2yEBV/uNEUKJmItSdg9an3WCmt+RjCkrxwq03zBqFjOvGQHyJDmLZmlfvBvV7mH4R9pHot+iECdqPiB7L1ru48EePiF9KBjCp6quRfWgecewC6P6lTMBeA/T7A5A8BUo81RwAvPNB5TKHmXR7gOV4nQEh6hc+pL9Ssuu01SPn7OUTrE9O4L8JnXo61tNko2f+h0LvnQPG7D6Hi3/4IvqDKtFizZ9NqirWth0+EB16UDY6iDNSv/MgC3PvUZpDWESDOR1mGQepwHpFALKsJA1Bz+hm89AI7GwZjOVrpLAAM99xviuX94Z0iwHVZcI4YBNhtIcfFP5rC+F0+qhpTPqWxlKsD8iDqwDHROfENrK2QmdRoSd0c1GfgPaHUTzvHS5jicZjmNhuAV7Frx4/kJ6HOq6okY5SPDe2zJqjGM+9FCc8UqPRJRvQFqvmvtimXlswek0UqnNukBlorJ19URcAFI4yzcyXYCDEkK5lHrpKx88pfzIDImSMCqTGnThhQvK5A32gma2n5ZVUSqC/ll07NN1/2jsULlLwUObrb8ECOH1TIDHwvf9YyEC38penZ/iBcY0NHzq40WiTI+OiSWAMYVHl1W82J/3afK1j9mxuxzvdDpdFlOpfo7ZPBwAEcKSKQJuzfXtoy+cKwdWPb+sl8G/B01huUwVE0jX4THXKMZvY6Bso2lDCeHMON8g6xYnmD1HgHv8gEEJPsoIyZwdgrkOuJPDoRh4cQ59ZuZ4ZrvguOJzp7ZZrNYIzt286mjn7WB+lcfqzX0oK684pfda4C83Iker8MXiZtvNROzj9jYP F8TOsK0M Vh6h0kohx58yDZLWPA2tpBnm1ZrbtAkcOhuaW2q0dDlNZC2+Wp6UWavf7DFE5iFv30HmWsxyQ2/CLUMY5D4eCoZYNBXZ3rLGYJh0s/ktRJjZ8jLrEahubSJu2QtQXso+DlmK6dMihlkjxm5R2Z+mvL8mGZOt4/LZ7eKnSt+KhWQsHAJnpcTdQE+Nd/ViYsC8gzYAKswcXdDhzGZc0jqbd1mCoxA1A16MUHSnzw8rSMeYD0h1jLCWATiNEeeD/bFipQYRH3tYfuGfM3106FAXEt3Brw9Tm6ZRFYhQd 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: Since we have kmem_cache_setup() and have ported kmem_cache_create_rcu() users over to it is unused and can be removed. Signed-off-by: Christian Brauner --- include/linux/slab.h | 3 --- mm/slab_common.c | 42 ------------------------------------------ 2 files changed, 45 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index 52928474e6a1..7d79410996b8 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -269,9 +269,6 @@ struct kmem_cache *kmem_cache_create_usercopy(const char *name, slab_flags_t flags, unsigned int useroffset, unsigned int usersize, void (*ctor)(void *)); -struct kmem_cache *kmem_cache_create_rcu(const char *name, unsigned int size, - unsigned int freeptr_offset, - slab_flags_t flags); 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 515ad422cf30..90180f02a153 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -434,48 +434,6 @@ kmem_cache_create(const char *name, unsigned int size, unsigned int align, } EXPORT_SYMBOL(kmem_cache_create); -/** - * kmem_cache_create_rcu - Create a SLAB_TYPESAFE_BY_RCU 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. - * @freeptr_offset: The offset into the memory to the free pointer - * @flags: SLAB flags - * - * Cannot be called within an interrupt, but can be interrupted. - * - * See kmem_cache_create() for an explanation of possible @flags. - * - * By default SLAB_TYPESAFE_BY_RCU caches place the free pointer outside - * of the object. This might cause the object to grow in size. Callers - * that have a reason to avoid this can specify a custom free pointer - * offset in their struct where the free pointer will be placed. - * - * Note that placing the free pointer inside the object requires the - * caller to ensure that no fields are invalidated that are required to - * guard against object recycling (See SLAB_TYPESAFE_BY_RCU for - * details.). - * - * Using zero as a value for @freeptr_offset is valid. To request no - * offset UINT_MAX must be specified. - * - * Note that @ctor isn't supported with custom free pointers as a @ctor - * requires an external free pointer. - * - * Return: a pointer to the cache on success, NULL on failure. - */ -struct kmem_cache *kmem_cache_create_rcu(const char *name, unsigned int size, - unsigned int freeptr_offset, - slab_flags_t flags) -{ - return kmem_cache_setup(name, size, - &(struct kmem_cache_args){ - .freeptr_offset = freeptr_offset, - .use_freeptr_offset = true, - }, - flags | SLAB_TYPESAFE_BY_RCU); -} -EXPORT_SYMBOL(kmem_cache_create_rcu); - static struct kmem_cache *kmem_buckets_cache __ro_after_init; /** From patchwork Mon Sep 2 15:31:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13787435 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 06178CA0ED3 for ; Mon, 2 Sep 2024 15:31:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F2C468D00F1; Mon, 2 Sep 2024 11:31:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EDB268D00EF; Mon, 2 Sep 2024 11:31:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D307D8D00F1; Mon, 2 Sep 2024 11:31:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id B16628D00EF for ; Mon, 2 Sep 2024 11:31:36 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 34C6E41D63 for ; Mon, 2 Sep 2024 15:31:36 +0000 (UTC) X-FDA: 82520187792.12.DD01B4C Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf27.hostedemail.com (Postfix) with ESMTP id 6014E40021 for ; Mon, 2 Sep 2024 15:31:34 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=jaDjvsS0; spf=pass (imf27.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=1725291001; 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=g6e7KFPpIG16PWwOpKpL70u5HNRx4HzsGFpd8uMNSfY=; b=xvN56QkR+oaZyiTfLMmsr8TUxb2MY4DxQSYqeNta5wZuoQx5LPAYfINxPMXLzG5ZJm0JSu OHDRWWGQYc0D6gF8oDRdm+0/IEaiALlBvZrGaFik9Efdn1QX49qrOWeFIHB2Ks66vAW+8V a4JYZBFsUrAges4PTWSIDiDxiuT0ba4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725291001; a=rsa-sha256; cv=none; b=sApXo2m/xkq2d6+cXPfnPQPhwVFwMvPoB23yyhTcVO3CfwVY9uFGl73jlOAlGnoTjZZt06 aiO3nuVez1y3oaMEMyih2i55gPVsLC7TIRphNX+u7gL9njjP/0kv/ozFQY7eK6yts9Ut9c 8jsSY+H2cv92m81X3DadtMlsis1TGUs= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=jaDjvsS0; spf=pass (imf27.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 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 31D475C5889; Mon, 2 Sep 2024 15:31:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DDE8DC4CEC4; Mon, 2 Sep 2024 15:31:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725291093; bh=8MUKMhMzsFM3WWroXnvZDyHiTunVSLADhoPf2rz6oVc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=jaDjvsS0AW7vl0F9GWeOgsadz73XLD6YlDKkzpDmqKyVgQLWISiKOjPkNeLl6N+yP rJAn3zi2ejL37DIwplBVZA8BVXYi9gUkDIjnSZSM1MaXvpTEPhg+IJiVkKT4TNrj0v 1hiBPhas3N4NV3niFVfqhbgUn1ULSOnbgySHkoyHjkpVbkdpx8KrMxWPPa76a/EcCP joG25y+qmPYSNPzO72Q+ulGyhFLVHVsaRui5I0IAc/CQW16+n8avhE1B5A6Ok0ONmF WZbX1N/J9xuxVcf4q4Y6zSeMBJ8a9Q6SUaF1e2DXFQCq1FDIaJhEHwUGxSKTfJY/i+ qiWa1H+wt8miQ== From: Christian Brauner Date: Mon, 02 Sep 2024 17:31:16 +0200 Subject: [PATCH RFC 6/6] io_uring: port to kmem_cache_setup() MIME-Version: 1.0 Message-Id: <20240902-work-kmem_cache_args-v1-6-27d05bc05128@kernel.org> References: <20240902-work-kmem_cache_args-v1-0-27d05bc05128@kernel.org> In-Reply-To: <20240902-work-kmem_cache_args-v1-0-27d05bc05128@kernel.org> To: Vlastimil Babka , Jens Axboe , Jann Horn , Linus Torvalds Cc: linux-mm@kvack.org, Christian Brauner X-Mailer: b4 0.15-dev-37811 X-Developer-Signature: v=1; a=openpgp-sha256; l=1267; i=brauner@kernel.org; h=from:subject:message-id; bh=8MUKMhMzsFM3WWroXnvZDyHiTunVSLADhoPf2rz6oVc=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaRdveWhvmTLqpOPj134OeHWuYZ35yct1rDwt/sxcX2vV cGeXT2fJTpKWRjEuBhkxRRZHNpNwuWW81RsNsrUgJnDygQyhIGLUwAm8pSdkeH8Qp8/aWffucfx WGWdWFyZX52z8PnWC1+4nnSdPdwlHviFkWFxy4O3DQZMyyQ9WxZPXTJzdm+xO1db4Kqv3YdYNlt fbOADAA== X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Rspamd-Queue-Id: 6014E40021 X-Stat-Signature: usmq5g4913wp35mn3q17w6bq19wk3bj1 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1725291094-268893 X-HE-Meta: U2FsdGVkX18Hxqh0N04CeY2coRxejWEvWboEDgxGqnjEwwJoI94yErZgabnSS9VOupRmo3jgzvexZCFrbAdSZnTfdZlWPVI9ZD6+b2PKUrKRXWoSK0jg0KZ98qZyAVYC4XdB6+3ZHCUy+EaLe7jgcdLeW0qORNSySk9ifkncpWwTHpQBcjTOKXK4KF4FyRZ4I5Bmh/7nABJ1dXO6a1IBgxOgXDmf09i6EgOGT6VVyVhHBJga10/RBTpOyXEVg0nAuKlBMZpWavTZKwMCvYAfrDNGYXl+KHv7aLruw27jVaoJRRxg1jyOjjeCEl5VEZIzQjdo79mbdaQsK+PQOIuboA/muOeCrKRrv8IIjghGh2ve0wDa6edFilzkq+6esJclhF8Hh85fNuhYVa5QZe6kWq6JeDWY94tQdcHJ4/+kaQ5at2titPYDw/IiGZouFD7zJZirwBvXcwx/ywXzsnMTDoOeaoIaLaa1F6rkaqGgITZuH2nmYF53o7sey/TX12FD5eWVlHqK9HbYs88oc2BBkqfNp8eZsCo5dhl4XA+txmoPA2rIORvNiBnfbK2GlFJU91yNhssDOcZXD/motpA2wFV0UBGgCa64OrRYIChhCmcMxxehVLWLRMC0JslHGiGcM89nIITja23rTnvUjJuAr5THvEkRkeblobsUIKLNj+hAUerL12zYtTAySTA6GHvDkhg/6t9iIK45zealoWMKXepRzTVnX7LVVHh3sN18tFJwId/AYW1ShB5O5v9HjA6eF5pp4zDJMJ03YRDHI+COO+OY1CU5tRSRN8n88K6/62SlauyEiKdrkG7SRRD6aKSVE+y+QizJ1d0N1lrwEmsdPZlMwuY6iByp5h4VYVORMZ9W9X+bl9TfH44rqQQ7AyoufOXS6+ocVfTNsQ6y2mRfz4DkI/3hNi6elVYjUTfJTbYV30gaVZlWr43AVRe52tXdj3Cl6yfCQZupf76GIza ezLmiO0X Rbecvz4iym3JELw5I/c8B06qL/QFemNCo5GQpz5KUa2XA7TSVpQbQht8J5D65hPv8MuuI7bi4XwUHnjysYQQj6VsnMdlxMH/2LIpYH+7KCaWqT4ZsBexkx0vAeQc5CqAT0ifCXqbd772+agsERovDEA4gIIFGG81FuL1k+kguVJriXoWtl0T9K9SUzF+0CZCojGhDaRaa/ndW68bM0LyorKzLfATANZERiHj7dzKFBxNx+CkSEQGKcDnsiORk66sNdZlrEtUPK4Ko07Sf82rNREMnl4wfdKtRbEGZnor0FdcT5zs= 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: Replace kmem_cache_create_usercopy() with a call to the new kmem_cache_setup() function. Signed-off-by: Christian Brauner --- io_uring/io_uring.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 3942db160f18..092a43a63236 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -3722,12 +3722,15 @@ static int __init io_uring_init(void) * range, and HARDENED_USERCOPY will complain if we haven't * correctly annotated this range. */ - req_cachep = kmem_cache_create_usercopy("io_kiocb", - sizeof(struct io_kiocb), 0, - SLAB_HWCACHE_ALIGN | SLAB_PANIC | - SLAB_ACCOUNT | SLAB_TYPESAFE_BY_RCU, - offsetof(struct io_kiocb, cmd.data), - sizeof_field(struct io_kiocb, cmd.data), NULL); + req_cachep = kmem_cache_setup("io_kiocb", sizeof(struct io_kiocb), + &(struct kmem_cache_args) { + .useroffset = offsetof(struct io_kiocb, cmd.data), + .usersize = sizeof_field(struct io_kiocb, cmd.data), + }, + SLAB_HWCACHE_ALIGN | + SLAB_PANIC | + SLAB_ACCOUNT | + SLAB_TYPESAFE_BY_RCU); io_buf_cachep = KMEM_CACHE(io_buffer, SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT);