From patchwork Thu Sep 5 07:56:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13791881 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 AF1C6CD4F59 for ; Thu, 5 Sep 2024 07:57:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 407D86B009B; Thu, 5 Sep 2024 03:57:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 390846B00E7; Thu, 5 Sep 2024 03:57:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20ADA6B00B5; Thu, 5 Sep 2024 03:57:11 -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 F34E58D0001 for ; Thu, 5 Sep 2024 03:57:10 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 97F8A1219C1 for ; Thu, 5 Sep 2024 07:57:10 +0000 (UTC) X-FDA: 82529929020.03.A80B5DE Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf16.hostedemail.com (Postfix) with ESMTP id D3BA618000C for ; Thu, 5 Sep 2024 07:57:08 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=PV7TCy+x; spf=pass (imf16.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=1725522952; 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=GDW+dC6B32MFmyBg3N0T+Mv1KEQyjD1yi60gLpagBxc=; b=JZ1o4gAMzMH9Crdhs/kPiMTSp/PZ90gUf9xTQixbaTZ9shCNgboCaY/H168Q8BotsCzLsG 3GANWEsFTT6ahxqyJDOFmsCElJg7tgal4vu2QigA+NHv5r9q0zti7FBsDC/2HGR1u1mTsx pNy27LVgsb5CykuCV88jKF2ahXIbBrI= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=PV7TCy+x; spf=pass (imf16.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=1725522952; a=rsa-sha256; cv=none; b=f3mNPrecJnbdegRul3xF3Ru4F5GCphd7HL4MsDuQA+mn0gk2UghszIL/xhpJJ8Z4QrXKlR ZvFUJkmi8OYD6xgyprq5pczEyJO98gOAJ4EFnKkVBh75ELXCh8bDVLSEi2cb/6EGmykz/c D+6Q4gT2DzBsjGpFyqY84SX4us/W/OI= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id DF5E1A4437B; Thu, 5 Sep 2024 07:57:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62592C4CEC4; Thu, 5 Sep 2024 07:57:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725523027; bh=rY6kC2WiEYeQ/Zth3l+6kLSSBQxvb1BV7zU7+V4xp9g=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=PV7TCy+xlc5pai2T6OdADRXzqDCI7RS8Bew/YoEZlFm+l72tOIN19MbKrPF6i5xBM gOSOOQaJQe465NMdIBUFo+hbYDaRhYpDBiPbcDjqtRlv4DoS2DtOzj+tQv6cfdWBNb q0/i6dtuVk/rAoczLEeDpKbjTKcXRRWRLJDQAjn70rnQxzBUnrBpk0NSHVvzdefNjO RB4FHrnCps+DNwlrGxUABHRx3MBhNmetxyiNvz5dkhcGbVTYjn3mTBI+qXz7EvI+WC Y5xY+PYXXi78sd/hs7aUOS4++QZ8sdSPHGUlCFu1/5fer/b2UN8aXI5F+OehXTDhhW fKT+xPJB0wmuQ== From: Christian Brauner Date: Thu, 05 Sep 2024 09:56:44 +0200 Subject: [PATCH v4 01/17] slab: s/__kmem_cache_create/do_kmem_cache_create/g MIME-Version: 1.0 Message-Id: <20240905-work-kmem_cache_args-v4-1-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=2107; i=brauner@kernel.org; h=from:subject:message-id; bh=rY6kC2WiEYeQ/Zth3l+6kLSSBQxvb1BV7zU7+V4xp9g=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaTdTPEK4X7zku9Z8Eq+IAvWO5pVE032Bs03YHF2aUuIm s81MSG5o5SFQYyLQVZMkcWh3SRcbjlPxWajTA2YOaxMIEMYuDgFYCKFpxn+yoRdZjFudkjftsb2 yvpJ/zeGidzekMn8YGWqmMvE35bsexn+mTQ0TNHW08p6kHv/WRij7csO74MdNnfOrmJ8xKLl3sr MAwA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Stat-Signature: a4tcmzft14hj9eoh6yx4s71n6eefywu6 X-Rspam-User: X-Rspamd-Queue-Id: D3BA618000C X-Rspamd-Server: rspam02 X-HE-Tag: 1725523028-269437 X-HE-Meta: U2FsdGVkX1+AB2KYQhxzBUB0HJafF40hlnLCZZMF+ySZKq3OqBW71ORqOCRre+0m7v4beAp2GKkbUa7Zc6juiPdDRmRjXVaKt/snx4+Cm86gHsiqAbixBN8fPmvJS2WqzKvREx7JGyK90cPBF+WYQbdEnCaULt2BTnTzl8h8wLgB8l038R4G1dFO7O2EJ5wU5fBMgi2cod9cl38XhzTEZDywEWl9PNdLdhGJs0DwqwOHYM4mBdRsWWyJilMQY7qWSiLVJJTfCnwSTPs8np+ba0f5FY44Csvohs18sWmUu/vw2yP1VHuZAAF87fJr/KZneyA+7H3HJk5zyEQFZgESvKmvJfW1AyxmTeqLciuRUo/sRqLNvRe00m9ulP8jP5aUuMeXEwSV2jBclfDjC8nuXt19ZSQDYtyQiJDbWzDuyQTbqeDuiziTBK88S8+zEqYlL0cVt+a2lsiAP3AUpszrciKMalHl1cAWMsVqP6ze/BZwpLQKVSZFXoE1SMLIF0sO2gNkXBYbfgGA9Uzu5tRQH5JEn+T0yXq3+bhz0ZxSppKFjZcmcXN2/9fTk/GObHgreNqBot3XtkD+opmf5zvdqlYPjV3EiSXRKpILGT0DcA9J+NlMzruw58h+OOA9uehNV1x+p8pATh+7nbKt52vkXd7Mh9KxuBaXF0qQyaGtPDZZ0On5E8t+HLByPLwLWNuHGoHClt7iZYLt1edsAfQuwJrQXQzFIbFhECw5JOLz0lsy5FwMCCWgLc3nyG0NzQ49fiZTCya2kNPCUisnY0k0XWTgBSR+1UNsE9Xy9IOfm5H5Izyv9/6MZz7qN892pK9nqBagUcgkyg/zK8glcCi5Tv12dMVZ2O1jUOIHWkDA7+rz0h32oOFp4ylfxwIjv3BIDBQUuZEQVhCB6u8Zw84/7dIyXSA2fAdlZxkIpSWSS4yQWSm/u8oQgfPJIH/vSwvVUKtnutM0lHKs6DtcWK0 kIEv5jIJ g6FiRry7lITHlUbPx4/Lf3+5kEHwnoa0rJ027VYC5xd8VGW8rUUwYJS2CQSFORhroclslXTR9DMbw13BmvRRKy4wW3KggM9qBGJVfQuERAU2tJPVl9mSkkOzEuvGbH+KL0N+PEuu4RxETCC8lAL97poNpVWYjmikzeZQrW0cMfYDW361hxs1IuW6BL0NaiI4L22X04bpvhg0cT1Tggi8WEs2oBwye1WLF9MctoIB6ylT83BxgE8ANhX6Z6h3wV3rH7dTzNpIEsTEFFjJJb3CXUFoXy1F06t6xAIPQCsV+579+ewg5EdvmdiPllgoTxODww0AR/b9ChR4Dc+5m3NNUs74sPVcR2gAblQAtQBQpNuHpYAeFAcV8QWybXk1LbsCqYpNI47hlUnXZ0XEBH/K1AqRToryRlsh9XTHgsACP5VYr4Ng8IbRxXmdLndqqTYItD39c 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: Free up reusing the double-underscore variant for follow-up patches. 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.h | 2 +- mm/slab_common.c | 4 ++-- mm/slub.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/slab.h b/mm/slab.h index a6051385186e..684bb48c4f39 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -424,7 +424,7 @@ kmalloc_slab(size_t size, kmem_buckets *b, gfp_t flags, unsigned long caller) gfp_t kmalloc_fix_flags(gfp_t flags); /* Functions provided by the slab allocators */ -int __kmem_cache_create(struct kmem_cache *, slab_flags_t flags); +int do_kmem_cache_create(struct kmem_cache *, slab_flags_t flags); void __init kmem_cache_init(void); extern void create_boot_cache(struct kmem_cache *, const char *name, diff --git a/mm/slab_common.c b/mm/slab_common.c index 95db3702f8d6..91e0e36e4379 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -234,7 +234,7 @@ static struct kmem_cache *create_cache(const char *name, s->useroffset = useroffset; s->usersize = usersize; #endif - err = __kmem_cache_create(s, flags); + err = do_kmem_cache_create(s, flags); if (err) goto out_free_cache; @@ -778,7 +778,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, s->usersize = usersize; #endif - err = __kmem_cache_create(s, flags); + err = do_kmem_cache_create(s, flags); if (err) panic("Creation of kmalloc slab %s size=%u failed. Reason %d\n", diff --git a/mm/slub.c b/mm/slub.c index 9aa5da1e8e27..23d9d783ff26 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -5902,7 +5902,7 @@ __kmem_cache_alias(const char *name, unsigned int size, unsigned int align, return s; } -int __kmem_cache_create(struct kmem_cache *s, slab_flags_t flags) +int do_kmem_cache_create(struct kmem_cache *s, slab_flags_t flags) { int err; From patchwork Thu Sep 5 07:56:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13791882 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 3D171CD4F59 for ; Thu, 5 Sep 2024 07:57:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C45E88D0005; Thu, 5 Sep 2024 03:57:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BF6428D0001; Thu, 5 Sep 2024 03:57:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A49918D0005; Thu, 5 Sep 2024 03:57:15 -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 80FD48D0001 for ; Thu, 5 Sep 2024 03:57:15 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id F31201A01FE for ; Thu, 5 Sep 2024 07:57:14 +0000 (UTC) X-FDA: 82529929188.26.4F31AEC Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf28.hostedemail.com (Postfix) with ESMTP id 2B031C0002 for ; Thu, 5 Sep 2024 07:57:13 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RlCvUk1a; spf=pass (imf28.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=1725523008; 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=jxVftAYU0xDJ8Ce3plBhtpBX6qnB3UkHBV8DhWYp8Qo=; b=CK1Y19VPy65ecR4itxaC0awCYXiNzr0hH2wlOMV7+s4fMbyOqWS2ggGbrgxpaIit1fV8sE QYudCw+tbipLlzaTTUFiM+1zWM4lxG91g5Xw3GALBUfwaFvnRv+Vxro2mI0IJNzqJSLZE2 uMj6gXX4LfFT4CxDSD70yr8ktG2amzU= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RlCvUk1a; spf=pass (imf28.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725523008; a=rsa-sha256; cv=none; b=y7M2J2wzCsc4cvLQ3yLqTraHY/gnGGs+iwvvUviUMTtumiPt9YJlRB8DjC1FathCIYk/yQ /IyQYDi6Zp7hQDxdsVLXoEwzQRPIGEqNG4boJXgljWe05BC/if2QvMyvtURS9hR3mP+ktX oCm+d+5I77RFuePB5w+GzG/JBTEnIAc= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id A3DF65C555E; Thu, 5 Sep 2024 07:57:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 639DFC4CEC6; Thu, 5 Sep 2024 07:57:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725523031; bh=YrF0YLTWmhzO7ohK2/AAEF++N1Zrk2GGMPwzT5f/roQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=RlCvUk1aAW1A2PTD5pA5BLm8yKdG5h9Nt+M5LC6cKKQZe2I8dRntcu8FyPewu3x5J bPbBpiEdveTRgdl2rDXE02u69/PKcGxp4H2uFl4dCWQx0k4W96+0wwJ7e2MpqqErjU jiLHLqE0gCi9Iivb/u2ycl8NEWOIb4HS+0v/dgFWitb1THmhvyhD6XJXIOa/u9H+tv oLqtkwQfqy4mhDvTn2hhvtXkhRKGd4M5lIJIBbRIB7cH1wYLawsCDoihg623L76PHv 0ze59QHEhOpVT6y4uckiaW2M9CYoVqFlWcG1cYyb/+yuXiGNA2MakauPnqCJhQ3vg9 v/eKzN6tnn1Xw== From: Christian Brauner Date: Thu, 05 Sep 2024 09:56:45 +0200 Subject: [PATCH v4 02/17] slab: add struct kmem_cache_args MIME-Version: 1.0 Message-Id: <20240905-work-kmem_cache_args-v4-2-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=5895; i=brauner@kernel.org; h=from:subject:message-id; bh=YrF0YLTWmhzO7ohK2/AAEF++N1Zrk2GGMPwzT5f/roQ=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaTdTPFSL7jxYpd08eYXgeIGe5bWCPKWVF16ZvHq2XwLa 363/g6djlIWBjEuBlkxRRaHdpNwueU8FZuNMjVg5rAygQxh4OIUgIlozWb4zbI7r2Llq6MVPNum sxuH8z9azFfQ4R4//xLr78mf5jW9s2Vk+LRC82SZM8PUuc8EzDzOe63d90G9/pLulPkctmbFkdN 7+QE= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Rspam-User: X-Stat-Signature: 4hdeehmb39dp8u4xnos8x9oyrcjetwbj X-Rspamd-Queue-Id: 2B031C0002 X-Rspamd-Server: rspam11 X-HE-Tag: 1725523032-246491 X-HE-Meta: U2FsdGVkX19MDND9sxkvDA+eRkH3w2KZDPT4MoWNxCAJsXFYbPgSYulbKj8uv/gDi5Y6gNsi1JZ6gxgTE9isabsdPs1KLnQIH1AM3E7mGSnze1bhYgCfzyYOHA6gGQHTOt6ObBDMjKsbhSmMGLTpznXlUQZILBOdQe6odJ85hpbcPTIvGPmeq/h+jHIQbhr0YLN2h7Ctnbb7bvIzyNVF5ZWhSUND0oRmqLRuu8ka1BbNG7kmH+1gtdPD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+QCg3eZvHc8Qoy8fGIaAT3q6fbczlK1qPFssFPZb/Ww== 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: Currently we have multiple kmem_cache_create*() variants that take up to seven separate parameters with one of the functions having to grow an eigth parameter in the future to handle both usercopy and a custom freelist pointer. Add a struct kmem_cache_args structure and move less common parameters into it. Core parameters such as name, object size, and flags continue to be passed separately. Add a new function __kmem_cache_create_args() that takes a struct kmem_cache_args pointer and port do_kmem_cache_create_usercopy() over to it. In follow-up patches we will port the other kmem_cache_create*() variants over to it as well. 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 --- include/linux/slab.h | 21 ++++++++++++++++ mm/slab_common.c | 67 +++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 72 insertions(+), 16 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index 5b2da2cf31a8..79d8c8bca4a4 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_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 *)); diff --git a/mm/slab_common.c b/mm/slab_common.c index 91e0e36e4379..0f13c045b8d1 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -248,14 +248,24 @@ 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_create_args - 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). + * @flags: See %SLAB_* flags for an explanation of individual @flags. + * + * Cannot be called within a interrupt, but can be interrupted. + * + * Return: a pointer to the cache on success, NULL on failure. + */ +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 *s = NULL; + unsigned int freeptr_offset = UINT_MAX; const char *cache_name; int err; @@ -275,7 +285,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 +306,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 +323,11 @@ 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); + 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); if (IS_ERR(s)) { err = PTR_ERR(s); kfree_const(cache_name); @@ -335,6 +349,27 @@ do_kmem_cache_create_usercopy(const char *name, } return s; } +EXPORT_SYMBOL(__kmem_cache_create_args); + +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 *)) +{ + struct kmem_cache_args kmem_args = { + .align = align, + .use_freeptr_offset = freeptr_offset != UINT_MAX, + .freeptr_offset = freeptr_offset, + .useroffset = useroffset, + .usersize = usersize, + .ctor = ctor, + }; + + return __kmem_cache_create_args(name, size, &kmem_args, flags); +} + /** * kmem_cache_create_usercopy - Create a cache with a region suitable From patchwork Thu Sep 5 07:56:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13791883 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 F162ECD4F5B for ; Thu, 5 Sep 2024 07:57:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6EE0E6B0182; Thu, 5 Sep 2024 03:57:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 69D7B6B0186; Thu, 5 Sep 2024 03:57:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 53EC86B018C; Thu, 5 Sep 2024 03:57:19 -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 36ACE6B0182 for ; Thu, 5 Sep 2024 03:57:19 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B612D141A7A for ; Thu, 5 Sep 2024 07:57:18 +0000 (UTC) X-FDA: 82529929356.05.E57F91C Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf08.hostedemail.com (Postfix) with ESMTP id EC246160016 for ; Thu, 5 Sep 2024 07:57:16 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=n1yEAPYO; spf=pass (imf08.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=1725522940; 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=JlMDuH0GoVfadZtCSMXehXCNc32v8K9Oxk/OKwCILHo=; b=iAn7O8Ow2Fy4z1bT2kzU1p+en7z+wr1BNct5pZdGs0TchCswbWy5cngRSS5M623vgqAk08 g3hSUH4B94uBwgz0h9KoaW09nwg6UU+WZrZlfhsdxH1lNTY1Ouc/oAL7jt9rwEWpGYCiaN FKAo6U6LpTIqZ0klqtn4UrnDwOnBi7A= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725522940; a=rsa-sha256; cv=none; b=kOc//xSSQ3RyZp5+5+iQbhqm+VUJh+H8ieZgmkxi+0NAuuRrRgSQw66F8axl+KNSlGv51T Ej4H4o4wFWEHeqr9WjmLtI+9uNS2riXbsDEqmC5OjywwZdr6ObhfR5vwUEX7U9xtxErQgc lOkDc0IMV3P/BxzXVtH9MNMcPw0kkqY= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=n1yEAPYO; spf=pass (imf08.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 96E245C568D; Thu, 5 Sep 2024 07:57:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 624BBC4CEC3; Thu, 5 Sep 2024 07:57:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725523035; bh=GREA3sYaJRn8q3FSMpLjOkkur0kW09aZN/fas4uylbs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=n1yEAPYOkhFGaueY8PxQNM4lK424wC4LLcA4VZoAvb5sRDnTnUifIO/WWNvg15+c/ 96l0X4SE43ZRjAj/nvkbLg0iz5LROt+spWqSPPq2Txpfg7cSNT/Xz2E2WqOpJZdw5D lFRk0NfhYGoH7+UQIyDyVZc9fWNIfgPJaBG7ofLXjCVb0EVzcm7SSJ42nymshXMfe+ /D4Wk6cfDKl6Bd4QkWanB6UptwyqN34Wy2BO7glxcb4C0nXfVsAoM6q1Qo8ZLO2pJP ODo9PzM48pFQfM+m3oM7RCNDYwGgXrjv8vh7tPt4xxUrBY34iT/H0MdLerLxsImKvW oa/+9x27JXu5A== From: Christian Brauner Date: Thu, 05 Sep 2024 09:56:46 +0200 Subject: [PATCH v4 03/17] slab: port kmem_cache_create() to struct kmem_cache_args MIME-Version: 1.0 Message-Id: <20240905-work-kmem_cache_args-v4-3-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=1010; i=brauner@kernel.org; h=from:subject:message-id; bh=GREA3sYaJRn8q3FSMpLjOkkur0kW09aZN/fas4uylbs=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaTdTPHa0lwdyv1ebHdoTLLK7L1hdrPXNizcXFIZcJw/9 OjNO+2cHaUsDGJcDLJiiiwO7Sbhcst5KjYbZWrAzGFlAhnCwMUpABP5+oLhv2d7+4ofqTcu5jDm sq7rXHiimsc2YkPJs6o1ZgeKwyOC5BkZPlRMu3Ap7vgjqcV1UbX2r95Oyfi5J+0L61L/Hq6MW9z 9vAA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: EC246160016 X-Stat-Signature: zrq6qdw3fquckhgp5j55nbf1rgj5dy1k X-HE-Tag: 1725523036-236617 X-HE-Meta: U2FsdGVkX1/KQ1f6K+8dRpxNaJP6XE3qRZzKqzpJ48PNtI6eF43r0QUOvblWjV57BYN84Cvgb/XNO8soyRFT1pFkDyhUIqutrP4thrtSDHbu9qz2bc1HTo6E1WWVITvyxy0waWorbpHLJvJDw3fj1MOrrvWAssuTAVFyb4JgO6cUWNim6la7ITlr+3AfNDGkZHmXQXjPB5lw/DlJ3WSJA7D7q6re4mxH8C45b3G8E9739OMLLwiSgg82bmSlX5c2LEVhqd/H/0wxsdOrJIw4f9oQANNdS0ORHs3LcP6nWcsjlbFj9wfvUtZbVlg9M4iKKfeQQDWfViJN7qD6Z+lkgdBYGh+RGYMB5GzB6cm89jv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org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Port kmem_cache_create() to struct kmem_cache_args. 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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mm/slab_common.c b/mm/slab_common.c index 0f13c045b8d1..ac0832dac01e 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -439,8 +439,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); + struct kmem_cache_args kmem_args = { + .align = align, + .ctor = ctor, + }; + + return __kmem_cache_create_args(name, size, &kmem_args, flags); } EXPORT_SYMBOL(kmem_cache_create); From patchwork Thu Sep 5 07:56:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13791884 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 8D8A1CD4F59 for ; Thu, 5 Sep 2024 07:57:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2328C6B018C; Thu, 5 Sep 2024 03:57:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E3396B0193; Thu, 5 Sep 2024 03:57:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0AC446B01A5; Thu, 5 Sep 2024 03:57:23 -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 E015F6B018C for ; Thu, 5 Sep 2024 03:57:22 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A6011C0848 for ; Thu, 5 Sep 2024 07:57:22 +0000 (UTC) X-FDA: 82529929524.17.B6E16D1 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf06.hostedemail.com (Postfix) with ESMTP id CBB8A180009 for ; Thu, 5 Sep 2024 07:57:20 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pZmgX8C5; spf=pass (imf06.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=1725522992; 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=R0FJ7EEAyT91kPnU/k7OeBfuL6MkGhh8HVPdTieSOXM=; b=qs14DQyylnlymxRBZ9YYyQkzbZUTvWHGiDQMm/h9TpauUBJsOSOnXSibFNMH9pfXq9kU7M mvLhEXDcr0/o4x2xtHxJV5r5DJkJvqzbqNM110SAc1N21i/bJy4wG+vAp4jWH4rJeBinxz jcwSO+nAMU+X11C0L7KGxlKqzo2HVp0= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pZmgX8C5; spf=pass (imf06.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725522992; a=rsa-sha256; cv=none; b=CmXSUuy4LLGp0YfDy/I6KT42Bwa3R2Pw2GGhDRYwA0e/oEmKfYncGz8YGqU3tb1QNLzPyB iEkqFrN3WHJ+ANfW8sJ3oh51NaYKkEqp4qGo6HNO7SZzxxSCNIb43D5fTMyVbU5bN/AlTq 4wm/al1RGN0N/D57oJa3mPPgTOGSuAU= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 875035C433F; Thu, 5 Sep 2024 07:57:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F658C4CEC4; Thu, 5 Sep 2024 07:57:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725523039; bh=yFwPV9RImMNE3Jd/xX3WyJKu7K+3lEbT+HKSODA016Y=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=pZmgX8C5yhojHGzSpwIYVN1O8utd8eTeLfdJ+KCv8Vq2ZO5b52/05Pm9H3KqyU9Sq KvxnTBeWV9EhLSJMPdcmuc8CcLt8l1dDGMfDb7IKtrjwwFUfYWiPmPCaC3zwNGQLVv 1UychvUaOYnSlbFnpF0RBzzuiI6FDN4e2JsiHn4W6UvPYT1xRC7ZYyltk5yrG9OmPl XskKQWIaXsjwZ4rxWuBORBXonKDQC7cmwAb2l7a61JT1WYOE0KwjZKZh7N7HpgXgWb 4nTvRSeFZgNbpVuX7XD3mTpt4gLCfZGcoTm1paEOrUvgjg0Ve5wFXFHy0idr+l5LP4 5uSsgI5j5WxUQ== From: Christian Brauner Date: Thu, 05 Sep 2024 09:56:47 +0200 Subject: [PATCH v4 04/17] slab: port kmem_cache_create_rcu() to struct kmem_cache_args MIME-Version: 1.0 Message-Id: <20240905-work-kmem_cache_args-v4-4-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=1121; i=brauner@kernel.org; h=from:subject:message-id; bh=yFwPV9RImMNE3Jd/xX3WyJKu7K+3lEbT+HKSODA016Y=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaTdTPEqyfVkZ/Lj+7FDdPbsN+wabw4veVAVw1Dp/L6yh 1tta6p2RykLgxgXg6yYIotDu0m43HKeis1GmRowc1iZQIYwcHEKwETebWZkWJdyJGSWRv2/JNut Rf8X2y3aqBSctErO9RKXB7feo4PxlxgZrp64x/5lh85xJQ5hG0E+iSWFzVsOqEx4/f12rLuN5oX 5XAA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: CBB8A180009 X-Stat-Signature: bky44sfbd8cpg9i9r3mpqnkuhidqff7x X-HE-Tag: 1725523040-470876 X-HE-Meta: U2FsdGVkX1/cEjkeYsY0rRyvk4HtuS2icFO9Ufu6cP7TQltXDNWnZY1Y2cYC7XLYyMKJa26vNpLdIQiIAvP1AYbrqMDMmV1e4BcLT8VlAyTtHnUkqkusEZ+qwZxiMHidbFIC6XBeNGv5su3Wms1WPLmcHii2aY13n/cuP5aXfE7OgZCi3VY9EXF5CS1gWfkujexX/w0/XME8cdhV/qrJZEy4RgkNWbsP0ZcVi2Nl2WF+4dDMCkE9OnNlIOIGx0Ys5nyWpp3kD75jJTfco3qG9SBUofVmqnFUJ/KZtcUvCkaDyzb47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D2LIAaw7tsA== 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: Port kmem_cache_create_rcu() to struct kmem_cache_args. 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 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mm/slab_common.c b/mm/slab_common.c index ac0832dac01e..da62ed30f95d 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -481,9 +481,13 @@ 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); + struct kmem_cache_args kmem_args = { + .freeptr_offset = freeptr_offset, + .use_freeptr_offset = true, + }; + + return __kmem_cache_create_args(name, size, &kmem_args, + flags | SLAB_TYPESAFE_BY_RCU); } EXPORT_SYMBOL(kmem_cache_create_rcu); From patchwork Thu Sep 5 07:56:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13791885 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 859E8CD4F59 for ; Thu, 5 Sep 2024 07:57:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2334D6B0207; Thu, 5 Sep 2024 03:57:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E41E6B020B; Thu, 5 Sep 2024 03:57:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 00F256B0209; Thu, 5 Sep 2024 03:57:26 -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 D369E6B0207 for ; Thu, 5 Sep 2024 03:57:26 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 519A3C09EC for ; Thu, 5 Sep 2024 07:57:26 +0000 (UTC) X-FDA: 82529929692.27.209BF84 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf13.hostedemail.com (Postfix) with ESMTP id 9BFBB20007 for ; Thu, 5 Sep 2024 07:57:24 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="R/D1P6TD"; spf=pass (imf13.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=1725522995; a=rsa-sha256; cv=none; b=imrNyq4b2PkVYIimMqjNuh1pwA7BRleW8/j9ez0IyXF6noerEmptf8qTH4t69Ff/XUVAPg bFCXEUy2FFTiAkb3OjIEw4oYkiUvYb06DHhTgOqGjJtM85cTgGZUjzBVyLUpqRLUHeHdsU KDvaZKLtzUw6KL7MFpvmD8/fHI0ugrk= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="R/D1P6TD"; spf=pass (imf13.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=1725522995; 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=5+G9qNnNibOPVizeOtt1ZuXdkZTUPqHhLY+eMhYoYUU=; b=zyfZLGeTASyce0/OSuPZNUyhjzWWUzmmB/Q0jmyGFuzf2iVAb7zXBk8EfAEnczOW8I0YQy LPUt+Jo4FCZdVIok4BNPQxew1qZWYw/PCGMwdIR5UWk1rVwOrmMSQ6e4GP19kAQcQMxIGQ CtnM/OgQFEQPbXw8w66r7d/vkzlsk5Q= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id BFE2CA4437C; Thu, 5 Sep 2024 07:57:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45DEDC4CEC6; Thu, 5 Sep 2024 07:57:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725523043; bh=6Lwr5vukmiiT/FN2uceSot6K8Ni/9MrZgxWKfDi+Qrw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=R/D1P6TD7i3UY0YoNJUwmFJ6UyYHcjDyPANa2Wlb5o90hiQ26zKS5AR/jkc4f4SEy YceSaYFbEZHm/C5PYEd5MAowgwnVp6kdP/beQa/V8vHmLlhdst0Xz1xWgKs0FkuH1+ kRbclNIQTlz5eexEo1D/n1agRtf/mXV9cXck0Yzr6cRT+LB+zwIebWhvkBdbQee3Q2 SnFAEKpZUub3Ye8AUkfS/JNiKoWP7Vh+Yrrg3dCuoORvb55B+KAXFtGKaXoZYcqaRg GErCg5kgnpSiSOWZql/CqFt4+pB8A7esVmSzAcsfb0+uGVxtIuu6szTo6w26XFuiOx 2HsMsH/RvcV9A== From: Christian Brauner Date: Thu, 05 Sep 2024 09:56:48 +0200 Subject: [PATCH v4 05/17] slab: port kmem_cache_create_usercopy() to struct kmem_cache_args MIME-Version: 1.0 Message-Id: <20240905-work-kmem_cache_args-v4-5-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=2077; i=brauner@kernel.org; h=from:subject:message-id; bh=6Lwr5vukmiiT/FN2uceSot6K8Ni/9MrZgxWKfDi+Qrw=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaTdTPGKsfyzU2iy6oqJdrum/37ZLHLyxDqPwI66x69/G dy/cZWns6OUhUGMi0FWTJHFod0kXG45T8Vmo0wNmDmsTCBDGLg4BeAmr2b4X3hDN+grt9yT67Il Ng1Zx+Lux4SrOv7fxsC34I5BRsWGYEaG9/ZhR62uTH6+RsrF4JPes3+/Ns2q3ugaI+X3Ysf/D67 XOAA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Stat-Signature: 8sf3e6ymthackw36fmgkbnqxhfhgremu X-Rspamd-Queue-Id: 9BFBB20007 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1725523044-535673 X-HE-Meta: U2FsdGVkX1928XbWvfwTpYEXDE8ANnTUUjh3bTP/GnJG3svXEo13WfFhTfVOIQ49E3NDcibQeWIwD4ZBIC5gOdcqR3ZwykTo2ObIGnaQS0mAAGwvggk0Tlr8lBP4vsU2ffL69ZIhTnRA1LdA/ZLO96Furh2hsEMZaml8Ap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l3C/LdFy4WinNJvr0tGTtBMbZNcFVouf+LMYIHK8qonVsdyTzuMVfBnSPEPMf1+/h5x0+DhhJQhZDdxD4YmCP2CU594CG+SRFsDuWcEP3ERZzgp1xI+8GJVM8lX28WOgD1+yAP/G4yhMTNNmDdG9YVmxT1UOY80j 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: Port kmem_cache_create_usercopy() to struct kmem_cache_args and remove the now unused do_kmem_cache_create_usercopy() helper. 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 | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/mm/slab_common.c b/mm/slab_common.c index da62ed30f95d..16c36a946135 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -351,26 +351,6 @@ struct kmem_cache *__kmem_cache_create_args(const char *name, } EXPORT_SYMBOL(__kmem_cache_create_args); -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 *)) -{ - struct kmem_cache_args kmem_args = { - .align = align, - .use_freeptr_offset = freeptr_offset != UINT_MAX, - .freeptr_offset = freeptr_offset, - .useroffset = useroffset, - .usersize = usersize, - .ctor = ctor, - }; - - return __kmem_cache_create_args(name, size, &kmem_args, flags); -} - - /** * kmem_cache_create_usercopy - Create a cache with a region suitable * for copying to userspace @@ -405,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); + 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); 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); From patchwork Thu Sep 5 07:56:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13791887 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 46F64CD4F5B for ; Thu, 5 Sep 2024 07:57:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C464D6B0253; Thu, 5 Sep 2024 03:57:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C1CAD6B0254; Thu, 5 Sep 2024 03:57:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ABDAC6B0255; Thu, 5 Sep 2024 03:57:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 8A4FF6B0253 for ; Thu, 5 Sep 2024 03:57:34 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 40F311219C5 for ; Thu, 5 Sep 2024 07:57:34 +0000 (UTC) X-FDA: 82529930028.01.402062A Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf04.hostedemail.com (Postfix) with ESMTP id 81BAD40006 for ; Thu, 5 Sep 2024 07:57:32 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ObpeGRhp; spf=pass (imf04.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=1725523003; a=rsa-sha256; cv=none; b=GEF6Xt4s9rybHj3Q/3iuFBXFX1c2xc+EL++k8SH3m0yIaXW/Akroal0LXbMsSrptd6Ixiq nhFYOBWI1frpDAr1ZiygFooTCoVSW/tVF5yQnVnbMzVGHFd+DepJOwV8zhJ9EfP02Pjx/W kfReuNqc8Edn1tuf+5lIS4y198B9Nos= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ObpeGRhp; spf=pass (imf04.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=1725523003; 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=fR15JKYr3nIrxBVSvmJg8KI8NnjqKFw8vV8l27FBH98=; b=EdnFWw6lsmHVk8M76K6RbHWHcK5Nx2Q8mfJ5utsr89do3iHTORGe5eWOJu6YqyJ5pPraeP lx5gjhcZerxyNAPL54ke465nKQ1shediSmXYOIwgdvlJTr92N+E0Qs26m5yi5tC4Pcld8u hHNqCgacwceIZxwAU8i2gnwJzxhtOnc= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id A4F8FA431BC; Thu, 5 Sep 2024 07:57:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29AD4C4CEC6; Thu, 5 Sep 2024 07:57:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725523051; bh=F4tMDDfenpBgeWRetu8ug4Xik9BM3oJX2qts2ZpcdrM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ObpeGRhpLdQ/xuBN6oc6xnWemMqwQAuRAUt5YcF7NoCkWvjhAwlxQWyj0YMXbjEnA xL+aJg6yRld7k9ZRH+ok+weCGJzWrsHl08suV/gG2HeJ3/bwtGoGhpv6BivMo7Gh/Y UVXJXgjKC/yBQHHnVSSqhpPpIc46SKUmR3BUjov2sSc1Mi+CfEyraqEvSHni4F3tkZ MzrzFsfHl0cO15XuhnUg81sW2N32QewmdDV6gkcmZXKczJ+sn1glfWxTCxgd4k3LwZ vyBL3URCpolzi5OPCOlGEedhX0Hvc+I3WaG+oV2yYW7weQgP4k4TnhHF4l50gtempi NTlN8VzUHGzvw== From: Christian Brauner Date: Thu, 05 Sep 2024 09:56:50 +0200 Subject: [PATCH v4 07/17] slab: pull kmem_cache_open() into do_kmem_cache_create() MIME-Version: 1.0 Message-Id: <20240905-work-kmem_cache_args-v4-7-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=4372; i=brauner@kernel.org; h=from:subject:message-id; bh=F4tMDDfenpBgeWRetu8ug4Xik9BM3oJX2qts2ZpcdrM=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaTdTPF+/LIxODE3/l71sjm8Yc+2flq/cFrAmkffmULnH w0LqTr5paOUhUGMi0FWTJHFod0kXG45T8Vmo0wNmDmsTCBDGLg4BWAiDBEM/4sL0/4K6YoFeClI L/9byMhqxCZcLfdt52Kv+x5Zwh/nCzMybM5ddf7X++DrBstaBVet+fJQ5/yETMadStuc6jZ9r9f dwgIA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Stat-Signature: sftem1pqy9subtcybxiua8bwuazk9yxw X-Rspamd-Queue-Id: 81BAD40006 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1725523052-96142 X-HE-Meta: U2FsdGVkX1/GSe+XD+BA1v8u4lwA9Y2K+cXWUDMbB23nFOFRtWf7CAI6+YTs+Mop8R30Hbrse6rwQ/YEKDkG6BQgPHpicEjSZ1J4J5wz5G1dqQCnFkw5pwW7YbpGRu6bUjJtn1oXdyUED6w7+ivxH7gIcZ49K/DBADrdErY6Ts5e4QZekjD8xY6s/QCskWAjWNP0bO9yhzMYvgFqelmX6Orpwy7tAb89U5DgIqWB4fY++bVmp0N+t/fPvvdPs9UoYNT06SU82J1foz8cqMHrErL5X/9j1Ya/eoIciUrbZBKFcQY5uTQl+eUGlmRdoily2/j7Il5prq2eGbqQoihe9nzazr017sLulL00/zceCNxn79YL5/Q1NsBxDP2z5/BOAoIbHiS8yMJV05Bgs8AHETz6gwrPblTdYmjxOZRBBqJ0cDDEyEpTaDFfJS7pMpm0WhRhWVjLvF7Fbiz7KubDiNaMGI097hJsbOe70drVL9FsGyloaVTuCEdbNtjGtCvBf1NAQbBpTtxygkJFLxNsKTbn11dxcuAU1yyND94hm+TZ/zGEzHEc0z9DjxmD3UDoTUem9ghXFO+bAJu0BET63UarKXZHV9intYQxDqYUqbD1lS1psf4yOtel05r9UOQbZO/pZmGpo8KXccPHIcEXm/D+b6Xs4vQXv7j2kAqDQvZr5WfVhrnI8TeqLSVoiRfUHhbXfZZEm11SA/lteFvGKIjQfJtJLdNlPUnH+k888OMmU37wcrRhU2bXxtVD9BGaKdZiCM2xr2I4xncAsGbf3YaQuE6m/fZ3+39Q/r8aOLCEqY3po3fnSsx9YqR69Eq7e+s75N9Jr+YqyFitbsdVRP0ng4R5dfIw6gCmRZjn1hJ9phkkdS6SsLl0BRp0cLe5pLyjEpSdgMTroTHysUty9lw3kiCvuW+fFcO3nfDXNR5ay+YNRLffi0Inx3TTPHfxa8o4LLznKnTttZIWS3V +X9QyRa0 n6G+kL79XusX85/H7sUzVhQTRvOvlER6oymK04zlWt62yr1DkLz/GTPLLy70bVUQbyYb4UKOyk8YEN99VbiWlZ7xLc/NnDh5Zxwonk7x78v5RzEmSqved01rtmKT6nrw6K5GPPcuxTQV11bceQanWH0X+DmpwLzOyAbFxsyp5TLhkqiY879iZZSRDgsKE5b0sqqsp+UkMHL7uZVdh33qXLXYYWht5NOebSFOInE0ZGfo55/ePUNpJXVNugJM8qMHoaBDYRiPnFSD4LjcGRg7cLZCFHXuEwFpi35M46yTb5oI1O2EBf6Ioa3Ts6iIwi8MYRQhxu+xk7/SVTQ4d5EPdB3OI0a/HB7NYmogPvSk2RQr+cj0= 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: do_kmem_cache_create() is the only caller and we're going to pass down struct kmem_cache_args in a follow-up patch. 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/slub.c | 132 +++++++++++++++++++++++++++++--------------------------------- 1 file changed, 62 insertions(+), 70 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 23d9d783ff26..30f4ca6335c7 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -5290,65 +5290,6 @@ static int calculate_sizes(struct kmem_cache *s) return !!oo_objects(s->oo); } -static int kmem_cache_open(struct kmem_cache *s, slab_flags_t flags) -{ - s->flags = kmem_cache_flags(flags, s->name); -#ifdef CONFIG_SLAB_FREELIST_HARDENED - s->random = get_random_long(); -#endif - - if (!calculate_sizes(s)) - goto error; - if (disable_higher_order_debug) { - /* - * Disable debugging flags that store metadata if the min slab - * order increased. - */ - if (get_order(s->size) > get_order(s->object_size)) { - s->flags &= ~DEBUG_METADATA_FLAGS; - s->offset = 0; - if (!calculate_sizes(s)) - goto error; - } - } - -#ifdef system_has_freelist_aba - if (system_has_freelist_aba() && !(s->flags & SLAB_NO_CMPXCHG)) { - /* Enable fast mode */ - s->flags |= __CMPXCHG_DOUBLE; - } -#endif - - /* - * The larger the object size is, the more slabs we want on the partial - * list to avoid pounding the page allocator excessively. - */ - s->min_partial = min_t(unsigned long, MAX_PARTIAL, ilog2(s->size) / 2); - s->min_partial = max_t(unsigned long, MIN_PARTIAL, s->min_partial); - - set_cpu_partial(s); - -#ifdef CONFIG_NUMA - s->remote_node_defrag_ratio = 1000; -#endif - - /* Initialize the pre-computed randomized freelist if slab is up */ - if (slab_state >= UP) { - if (init_cache_random_seq(s)) - goto error; - } - - if (!init_kmem_cache_nodes(s)) - goto error; - - if (alloc_kmem_cache_cpus(s)) - return 0; - -error: - __kmem_cache_release(s); - return -EINVAL; -} - static void list_slab_objects(struct kmem_cache *s, struct slab *slab, const char *text) { @@ -5904,26 +5845,77 @@ __kmem_cache_alias(const char *name, unsigned int size, unsigned int align, int do_kmem_cache_create(struct kmem_cache *s, slab_flags_t flags) { - int err; + int err = -EINVAL; - err = kmem_cache_open(s, flags); - if (err) - return err; + s->flags = kmem_cache_flags(flags, s->name); +#ifdef CONFIG_SLAB_FREELIST_HARDENED + s->random = get_random_long(); +#endif + + if (!calculate_sizes(s)) + goto out; + if (disable_higher_order_debug) { + /* + * Disable debugging flags that store metadata if the min slab + * order increased. + */ + if (get_order(s->size) > get_order(s->object_size)) { + s->flags &= ~DEBUG_METADATA_FLAGS; + s->offset = 0; + if (!calculate_sizes(s)) + goto out; + } + } + +#ifdef system_has_freelist_aba + if (system_has_freelist_aba() && !(s->flags & SLAB_NO_CMPXCHG)) { + /* Enable fast mode */ + s->flags |= __CMPXCHG_DOUBLE; + } +#endif + + /* + * The larger the object size is, the more slabs we want on the partial + * list to avoid pounding the page allocator excessively. + */ + s->min_partial = min_t(unsigned long, MAX_PARTIAL, ilog2(s->size) / 2); + s->min_partial = max_t(unsigned long, MIN_PARTIAL, s->min_partial); + + set_cpu_partial(s); + +#ifdef CONFIG_NUMA + s->remote_node_defrag_ratio = 1000; +#endif + + /* Initialize the pre-computed randomized freelist if slab is up */ + if (slab_state >= UP) { + if (init_cache_random_seq(s)) + goto out; + } + + if (!init_kmem_cache_nodes(s)) + goto out; + + if (!alloc_kmem_cache_cpus(s)) + goto out; /* Mutex is not taken during early boot */ - if (slab_state <= UP) - return 0; + if (slab_state <= UP) { + err = 0; + goto out; + } err = sysfs_slab_add(s); - if (err) { - __kmem_cache_release(s); - return err; - } + if (err) + goto out; if (s->flags & SLAB_STORE_USER) debugfs_slab_add(s); - return 0; +out: + if (err) + __kmem_cache_release(s); + return err; } #ifdef SLAB_SUPPORTS_SYSFS From patchwork Thu Sep 5 07:56:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13791888 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 596A2CD4F59 for ; Thu, 5 Sep 2024 07:57:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E1AC36B0255; Thu, 5 Sep 2024 03:57:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DC9AB6B0256; Thu, 5 Sep 2024 03:57:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C46B66B0257; Thu, 5 Sep 2024 03:57:38 -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 A51846B0255 for ; Thu, 5 Sep 2024 03:57:38 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 5E3D51A0A13 for ; Thu, 5 Sep 2024 07:57:38 +0000 (UTC) X-FDA: 82529930196.26.3804D5C Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf19.hostedemail.com (Postfix) with ESMTP id 961F01A0004 for ; Thu, 5 Sep 2024 07:57:36 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=lCMJJsA2; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf19.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=1725523032; a=rsa-sha256; cv=none; b=fcL+D4fD1WUSlJV17NSxvqSzS76quluMKTjrAthbzLRnvkdzaaRkoCNGsVrkcnLgzGT1Oo abhHIVA59NoEPmWH/U7ldYmx8HLTD8O0e10qsLSIUDpdXpVU/zGD6Bd1Wrxf9qFtS8CbxV fDlNdtsqYMNdz5ZQA2aIZuR56v3nd2Y= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=lCMJJsA2; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf19.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=1725523032; 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=ID7KRmdzDAcphg/Ijv1Oxd4c7RBfeOynWnxC9R+BJ48=; b=egVPsteBO1DxIEVqPIikJWnKf+dERPXczkQSHfPbW7UKAbu9a6rOizqwWdf/06BmBgMXjI JglrbT1bTLmf7mQijNWnQZNqto5VU9lN2Dz1N/+1m/yVh0w2ZwfOgLaiCeZDSJxQrTTa3v jfRkP+Fwy104EdcTp+j34GJbvcr/4iA= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 640C35C0F8B; Thu, 5 Sep 2024 07:57:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28B9FC4CEC3; Thu, 5 Sep 2024 07:57:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725523055; bh=68ks3+RK7luxREXLt0gNfsWbQ+8I8NfI8y27/qM8GTo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=lCMJJsA2FYQgZ241Y/sVm4oECKak0msryTpe6Sxy0xhPqrJ4bz+KhoUhxL14XWa1c 7E+aemB9oTGTfc5vf7ZjV6+34ksKJNjfyrwdWGGVBINGAM5bGQEHyfHw0aanRFgDfr 95fU5OABVDgKWclGHd20xyuZDsq+ffWmV7zDnzjhyo5D2a+9PoWQZhHl9tt8+dkT7Q UJVo/ISOhmxyzB8f/ZerRvzWyNLDq9UE4WkJcK7GI/AN2FVNQ96k1gBj2pqV6egzIm iGbxOz4BJ5tXpM1QhItXBzVswa4b1k2vJkjww2yuXsrYFWrJ7pQlGvB8rpGUrNO8TA TsQJqs2fi09KQ== From: Christian Brauner Date: Thu, 05 Sep 2024 09:56:51 +0200 Subject: [PATCH v4 08/17] slab: pass struct kmem_cache_args to do_kmem_cache_create() MIME-Version: 1.0 Message-Id: <20240905-work-kmem_cache_args-v4-8-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=4004; i=brauner@kernel.org; h=from:subject:message-id; bh=68ks3+RK7luxREXLt0gNfsWbQ+8I8NfI8y27/qM8GTo=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaTdTPHe0MpoGSi7d66U3P/akqWzzBdPLC8ol1nexlAr+ ncn67pdHaUsDGJcDLJiiiwO7Sbhcst5KjYbZWrAzGFlAhnCwMUpABOZeoPhf8l6tcjWzRWT1WbF 3H4W5XN1Ert36Ee5VbJvw3KvM/h5v2P4xbzkMcfhuDniFefderU3aERvNT+tKWEXWZq1K9iyqaC YBwA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Rspam-User: X-Rspamd-Queue-Id: 961F01A0004 X-Rspamd-Server: rspam01 X-Stat-Signature: fs9p1hw6ax7rzfn9fr99oxx868ncrasm X-HE-Tag: 1725523056-541096 X-HE-Meta: U2FsdGVkX1/tSg8c3e/nDbrZLxWtY9sVYDgJLlSjN+k8AXaQrFfg693Kt+ZDrgdzIzPG3YayVNvneD3Hx4RIsCJxPgPn8YKj3JvxzSCCJydHqTdtq+c/C3lCRcon3SCtQwHnG7Zd28PRAexehyScjAPpOT1ghIijjptgzFceDiG7t2VJteZtp7wdEamB12QekdaL5717CNOn4lgKbSvoctaxD7RIn7AB5C5+fW0u//tyRrWAjvoui+52ZsFSNcpugalbZVZTYMBp5ka3iqOOIFVMIoFOORghFz8byPjpl/B4RQQFt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, 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: and initialize most things in do_kmem_cache_create(). In a follow-up patch we'll remove rcu_freeptr_offset from struct kmem_cache. 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.h | 4 +++- mm/slab_common.c | 27 ++++++--------------------- mm/slub.c | 17 ++++++++++++++++- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/mm/slab.h b/mm/slab.h index 684bb48c4f39..c7a4e0fc3cf1 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -424,7 +424,9 @@ kmalloc_slab(size_t size, kmem_buckets *b, gfp_t flags, unsigned long caller) gfp_t kmalloc_fix_flags(gfp_t flags); /* Functions provided by the slab allocators */ -int do_kmem_cache_create(struct kmem_cache *, slab_flags_t flags); +int do_kmem_cache_create(struct kmem_cache *s, const char *name, + unsigned int size, struct kmem_cache_args *args, + slab_flags_t flags); void __init kmem_cache_init(void); extern void create_boot_cache(struct kmem_cache *, const char *name, diff --git a/mm/slab_common.c b/mm/slab_common.c index 9baa61c9c670..19ae3dd6e36f 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -224,20 +224,7 @@ static struct kmem_cache *create_cache(const char *name, s = kmem_cache_zalloc(kmem_cache, GFP_KERNEL); if (!s) goto out; - - s->name = name; - s->size = s->object_size = object_size; - 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 = args->useroffset; - s->usersize = args->usersize; -#endif - err = do_kmem_cache_create(s, flags); + err = do_kmem_cache_create(s, name, object_size, args, flags); if (err) goto out_free_cache; @@ -788,9 +775,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, { int err; unsigned int align = ARCH_KMALLOC_MINALIGN; - - s->name = name; - s->size = s->object_size = size; + struct kmem_cache_args kmem_args = {}; /* * kmalloc caches guarantee alignment of at least the largest @@ -799,14 +784,14 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, */ if (flags & SLAB_KMALLOC) align = max(align, 1U << (ffs(size) - 1)); - s->align = calculate_alignment(flags, align, size); + kmem_args.align = calculate_alignment(flags, align, size); #ifdef CONFIG_HARDENED_USERCOPY - s->useroffset = useroffset; - s->usersize = usersize; + kmem_args.useroffset = useroffset; + kmem_args.usersize = usersize; #endif - err = do_kmem_cache_create(s, flags); + err = do_kmem_cache_create(s, name, size, &kmem_args, flags); if (err) panic("Creation of kmalloc slab %s size=%u failed. Reason %d\n", diff --git a/mm/slub.c b/mm/slub.c index 30f4ca6335c7..4719b60215b8 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -5843,14 +5843,29 @@ __kmem_cache_alias(const char *name, unsigned int size, unsigned int align, return s; } -int do_kmem_cache_create(struct kmem_cache *s, slab_flags_t flags) +int do_kmem_cache_create(struct kmem_cache *s, const char *name, + unsigned int size, struct kmem_cache_args *args, + slab_flags_t flags) { int err = -EINVAL; + s->name = name; + s->size = s->object_size = size; + s->flags = kmem_cache_flags(flags, s->name); #ifdef CONFIG_SLAB_FREELIST_HARDENED s->random = get_random_long(); #endif + 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 = args->useroffset; + s->usersize = args->usersize; +#endif if (!calculate_sizes(s)) goto out; From patchwork Thu Sep 5 07:56:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13791889 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 0F9FDCD4F59 for ; Thu, 5 Sep 2024 07:57:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9D4E36B027A; Thu, 5 Sep 2024 03:57:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 985106B027B; Thu, 5 Sep 2024 03:57:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7FE2B6B027C; Thu, 5 Sep 2024 03:57:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 599526B027A for ; Thu, 5 Sep 2024 03:57:42 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 0AF07A8AA8 for ; Thu, 5 Sep 2024 07:57:42 +0000 (UTC) X-FDA: 82529930364.02.F9851A7 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf30.hostedemail.com (Postfix) with ESMTP id 562DC80016 for ; Thu, 5 Sep 2024 07:57:40 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pT0XIJG5; spf=pass (imf30.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=1725522983; 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=DOyAi7qM8AtwRcwRTnqSXMpj3Hh+qEljTsbAw6OkFXY=; b=fWardusa5gg5+z60Vgpovxon9aKBvQEHRDXIWhYp60jHcoggWgCLyZvt93exlfClBLCuBo 84thPQKIh6gRHEX3zIASvoSlV+YUzAT6VdahnIJz82HeBPvGq5Sw5LCqkK0ZTCMMqgyZ/t M3EedYR3W7lPvjelrbSwGZHkDiuN3eM= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pT0XIJG5; spf=pass (imf30.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=1725522983; a=rsa-sha256; cv=none; b=ll5bSw2PWG8qkalUGqALjMABeg+Ha2lAKBb+/8IyPqFwo/WXRl9gF0i0M5RfNX9lRGwvKk fi323rCyUAAcf9kUzSmbqAffxffdaWluU+xceuexRinYQh+kdqke/Zg5tKpHOZu5W/XzuB Nq7bpSMzoietUnZ7WexvHYWM7g0Rrn0= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 6DB81A44372; Thu, 5 Sep 2024 07:57:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E0B0C4CEC3; Thu, 5 Sep 2024 07:57:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725523059; bh=Zf6O0R24GKVW0QtPgh/qra6wApA/id2hJZ9TPx/ME9U=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=pT0XIJG5jf6UweHnX3PnusUh7KGghRnwnSRbHnn3xA4ShIU+NmamAtaK6vBrYk2mi H6So88w+HbyvPAA6PDRnnFNIX0mSLfAAN1ytfggZbn5Czz9MLNbo0wEr/26NW+zctS NbjwmB9y12/NwWbSHwQ95npLdiS3NL9NjuEc79Da+qVyQ3KrGqzzXIuDfMpyu6Z60L 90wpyQFvLYUI15pVE3ZdqZtstQx6165hHWkrJaTTk9Y1v70sc8xzly8D/iwtpDHXlq FrL8ueGzjJSOMor9BAJg0BpmFwFpTKugigsDRLEcIUjr0aax7uYvEm1co7kpgV+KT8 qFafnPFKwZwwQ== From: Christian Brauner Date: Thu, 05 Sep 2024 09:56:52 +0200 Subject: [PATCH v4 09/17] slab: remove rcu_freeptr_offset from struct kmem_cache MIME-Version: 1.0 Message-Id: <20240905-work-kmem_cache_args-v4-9-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=3996; i=brauner@kernel.org; h=from:subject:message-id; bh=Zf6O0R24GKVW0QtPgh/qra6wApA/id2hJZ9TPx/ME9U=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaTdTPG+VWf2/MDpjftOT9Dq6BX8s4SRRaTC3vkMS+kit vQu1Ze/OkpZGMS4GGTFFFkc2k3C5ZbzVGw2ytSAmcPKBDKEgYtTACbCEsjwh2d513G2xGq1PKvE d3ETuZ0Wbma+rL342ZUPPB2sn12X2jD8L0n7/Zo7ePHZ5tUKqYdmx3dnZx0WiJ1mnrW6d0fuGlM dbgA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Stat-Signature: uz99xzq1dynb81ssixtsw1qx3dcerb3y X-Rspam-User: X-Rspam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8TLRFljmfBoGXHAIz9gFRnfljKLecxTDw9p7oh/7gdImOcJXwVl2yFD7j7J8J+W9fNyMfb62s5MbkR+by6VFoo8IBm4dkO5DeXT0v3uElp85kCuD1tBqyxk6hH4/t3+VobhwuxU7br5GBTfA91101kTO56gWxOmHYLsBwrMoAz/63KIJUS3QHrRwpECIaa4Hi9krprtWolEmA3oQWxlXRQc0efIOz/aoyOPFgjvI1XeA4r+gx5+zXVDgehKFmpOKERoz04ey4W+x34KJFkus+73aBRXeomE1vDdUeHYQ9owsqpVydouZxYdlmP7xmH8vycM0u1m1xJYlYn2POb2zQkDHvJjrVMU+70OKOoWJlBc4VMcXsTjAuE= 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 down struct kmem_cache_args to calculate_sizes() so we can use args->{use}_freeptr_offset directly. This allows us to remove ->rcu_freeptr_offset from struct kmem_cache. 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.h | 2 -- mm/slub.c | 25 +++++++------------------ 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/mm/slab.h b/mm/slab.h index c7a4e0fc3cf1..36ac38e21fcb 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -261,8 +261,6 @@ struct kmem_cache { unsigned int object_size; /* Object size without metadata */ struct reciprocal_value reciprocal_size; unsigned int offset; /* Free pointer offset */ - /* Specific free pointer requested (if not UINT_MAX) */ - unsigned int rcu_freeptr_offset; #ifdef CONFIG_SLUB_CPU_PARTIAL /* Number of per cpu partial objects to keep around */ unsigned int cpu_partial; diff --git a/mm/slub.c b/mm/slub.c index 4719b60215b8..a23c7036cd61 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3916,8 +3916,7 @@ static void *__slab_alloc_node(struct kmem_cache *s, * If the object has been wiped upon free, make sure it's fully initialized by * zeroing out freelist pointer. * - * Note that we also wipe custom freelist pointers specified via - * s->rcu_freeptr_offset. + * Note that we also wipe custom freelist pointers. */ static __always_inline void maybe_wipe_obj_freeptr(struct kmem_cache *s, void *obj) @@ -5141,17 +5140,11 @@ static void set_cpu_partial(struct kmem_cache *s) #endif } -/* Was a valid freeptr offset requested? */ -static inline bool has_freeptr_offset(const struct kmem_cache *s) -{ - return s->rcu_freeptr_offset != UINT_MAX; -} - /* * calculate_sizes() determines the order and the distribution of data within * a slab object. */ -static int calculate_sizes(struct kmem_cache *s) +static int calculate_sizes(struct kmem_cache_args *args, struct kmem_cache *s) { slab_flags_t flags = s->flags; unsigned int size = s->object_size; @@ -5192,7 +5185,7 @@ static int calculate_sizes(struct kmem_cache *s) */ s->inuse = size; - if (((flags & SLAB_TYPESAFE_BY_RCU) && !has_freeptr_offset(s)) || + if (((flags & SLAB_TYPESAFE_BY_RCU) && !args->use_freeptr_offset) || (flags & SLAB_POISON) || s->ctor || ((flags & SLAB_RED_ZONE) && (s->object_size < sizeof(void *) || slub_debug_orig_size(s)))) { @@ -5214,8 +5207,8 @@ static int calculate_sizes(struct kmem_cache *s) */ s->offset = size; size += sizeof(void *); - } else if ((flags & SLAB_TYPESAFE_BY_RCU) && has_freeptr_offset(s)) { - s->offset = s->rcu_freeptr_offset; + } else if ((flags & SLAB_TYPESAFE_BY_RCU) && args->use_freeptr_offset) { + s->offset = args->freeptr_offset; } else { /* * Store freelist pointer near middle of object to keep @@ -5856,10 +5849,6 @@ int do_kmem_cache_create(struct kmem_cache *s, const char *name, #ifdef CONFIG_SLAB_FREELIST_HARDENED s->random = get_random_long(); #endif - 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 @@ -5867,7 +5856,7 @@ int do_kmem_cache_create(struct kmem_cache *s, const char *name, s->usersize = args->usersize; #endif - if (!calculate_sizes(s)) + if (!calculate_sizes(args, s)) goto out; if (disable_higher_order_debug) { /* @@ -5877,7 +5866,7 @@ int do_kmem_cache_create(struct kmem_cache *s, const char *name, if (get_order(s->size) > get_order(s->object_size)) { s->flags &= ~DEBUG_METADATA_FLAGS; s->offset = 0; - if (!calculate_sizes(s)) + if (!calculate_sizes(args, s)) goto out; } } From patchwork Thu Sep 5 07:56:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13791890 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 CAA7ACD4F59 for ; Thu, 5 Sep 2024 07:57:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5B7666B00C5; Thu, 5 Sep 2024 03:57:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F0016B00E1; Thu, 5 Sep 2024 03:57:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 392B86B027C; Thu, 5 Sep 2024 03:57:46 -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 146106B00C5 for ; Thu, 5 Sep 2024 03:57:46 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id BDFF7819FD for ; Thu, 5 Sep 2024 07:57:45 +0000 (UTC) X-FDA: 82529930490.02.E2017CF Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf09.hostedemail.com (Postfix) with ESMTP id 10700140005 for ; Thu, 5 Sep 2024 07:57:43 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=KYwRNlCa; spf=pass (imf09.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=1725522966; 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=xduX72Kh/2IKT4jxLVbqqUzZkl1nUopJtgcqKapU4zI=; b=QPPV2ovgNV1P+u2i+cFwtluSuoJ4X+1RhUBiPtKw/ty84aDL2aeQvRsOeOtFnor2Pnw+FF UNCCtCdljHZBfA0UJBjrmoR7ab7PFl9755LgV0taI63h5D9PFlCp4VKRD2B2Ngt94GK0c8 h2nLNx3XMe5d/87tOtIUDQab8V5FrbA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725522966; a=rsa-sha256; cv=none; b=ZqXhXGHP1aSmecEFvLMSoYHGIRrF8Es6lzpOunwoq+yUA3Cg/Kgc7lLC/lgOjAu9I8YY76 I2sO9qBy1jpnWu4mbnyZ5/aMnw3pnxB+ggsQiMO30kAdXnLACf/Ao7K8pZxfYarvBc+2He dGtW9f1OD6eNZ8/4oR8YL3GJ4OyhGk4= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=KYwRNlCa; spf=pass (imf09.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 3A7FEA442EA; Thu, 5 Sep 2024 07:57:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE3E7C4CEC9; Thu, 5 Sep 2024 07:57:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725523063; bh=R+pPpbtSd7TpTn7/geWedM/ETd5BwUD/V+znBniHb4Y=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=KYwRNlCarPHqMLpahTJxt9QurLzF3yW5roIRbxWkYPvzJJeQxMBhK7l4eQPQ+zUht M35sBmieTcbswH4nzib0mhw8RkFBbOqAVbwmmHU/OoHbSo+qB5RbqoTlg5LgtpiJe2 ZxpUT6My1K+7df/sHXZRyMCZD2v3O1xaGGVp+MqlJnCgWYQ/wIJGJMqKmACLK3cJ+u G4sRZDQEHpyvN7XmyRv1T/t4BPteuRlJefS4jEDwUV2FT73yONODrCuVq7wpcJM1ys YdyCNYyN9RhyV2tdcMgFXEMBTQ52q883ZbY4PYRf8JCyL/s/t7Lrf31llAmmhfYMSL dBWL4YbTmXV/w== From: Christian Brauner Date: Thu, 05 Sep 2024 09:56:53 +0200 Subject: [PATCH v4 10/17] slab: port KMEM_CACHE() to struct kmem_cache_args MIME-Version: 1.0 Message-Id: <20240905-work-kmem_cache_args-v4-10-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=1255; i=brauner@kernel.org; h=from:subject:message-id; bh=R+pPpbtSd7TpTn7/geWedM/ETd5BwUD/V+znBniHb4Y=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaTdTPEOPOFxrsVP6W3YHb7n2U915Ges537TFGG2fOPb8 1fEzcPNOkpZGMS4GGTFFFkc2k3C5ZbzVGw2ytSAmcPKBDKEgYtTACbSac/wP3tipJtDqcTMiBy3 Uz/2yU1fupp34Z1bnKeOmxTYdm70vsPIMF3joN7yQj2NZT5p5Yv6JDZw2WS0GUv95Lu0YtZkqcX izAA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Stat-Signature: ikmcwm6ekrpuo7ufytfo71ot8rf59qbe X-Rspamd-Queue-Id: 10700140005 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1725523063-8294 X-HE-Meta: U2FsdGVkX18Z4a+L47bsUFmRkH5CstB7SuRFxJo8DX54yjMhhteM+vFuvrERfx9og8M0M0IbGcqZXgr9S6CN7wcIGmpMylnqych3DNwtQ3x3egG3AKTUlAq4BtQmDwsyKiyALXWz5ilRtuvYas87/ctss6xP6iVGHqMH0s6rNo5jJ8ILHr+Q9OXvZqzjtLikGxizUCrX5DYNmFawkZy/mMTFW4KahboUGIRLVFN72b0/+1xbttm+fdwp1lAvUVhMGgg3AIR+cwHnn2HfLR9qkb178OPXxWdcROrk0nmcECwpt2248PRleCQVO+f7FC0FEsE0SumN5axMVfAO4Ddp21ClqWmkeyEt+kylGInt3B9/Vu0serDO82Cvzam4wE0lz4ZaU5KkPdVjS97HQRev7Gz9ZvQ/pYs5uESdJhxxcwMvP26a1q8axbIHEjj6MILBmmRjrYP88tELFZDyip40LBz4PEQ+dCHggCOsc4kaOAfjgQ8WTRMEH6iDZ0MJxE6QzsSVTe/jlni/0YvZ2cs0NF7+DkTid5xEac1iFN/iuxMJJ+cMpXsv3QXs0wnp5zF5MDYGTLHO/fMF8iXjMkjHMDhXiXDlV7VPVA7Kq5VL/0zsxtdL2v99Dz7hnHsHcdU7LGQSJ1tjoHBkfesq7RECxIsULiedtLVJr6+3AIYaH6FYmVUy6Iy5JVwyHLXnF/Y6iz2b2s6p3rykwbuTo6akR0F+JhUy9FYIu2ozrYE1pPk4NWSXN78kmNwSQV1dHQl0RejDSVkEHd9JGZCXgIdBHS14SSRQNr6R0o3DckvaO/d5AIOQateKOX4VgDLKrYgZnX2x1ntDNx73JJa0H4CnCujf9SPU4owvXa37Jy5YVIWf0zU4+YO4WGpy3LXnO61y72FS/aOR/HsE45ODpd7/SCanXOYvzo2poFeQ3DAaIgoB8BOat4HA/+STrUYV5/X88ji3DJzkblXYSu+ynMe YK2TL1yj Mc4YHkVcndg0eH2R5DEWIpZIkdbWSs8ScTKVjCgKTYvRuPgi3nwB2oq7j1OLrVIcNzID9S/T4vGWL80/id9gMZPtfhJw6OGgbUKU6joDdqeWkttdzVJClNkJVv8XQkHYmqbQB9pxxkn7ynqLaTVoXs+S99cMX74gRPlXKF0gqPYexnecn7WjN7ZRGIhSMKBM6q8K48s5l/MjZtonmgBHREU68ND6S55ydi4A3Jvu8aUQEOcGpRZd8KMTMfGIv6aBTT+0V6WZIexpV3kYxl/a4qPppALV1fNT9Ti2SCI9YsvYxlTQCzzLZh49t34RCSm/7Oty4bhSVECAQy3aX3pb8xAPR5bp+/ORInsavsf3e2g891RlZklRaZE49XHR533TFzHDNm2NijyY28ns= 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 struct kmem_cache_args. 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 --- include/linux/slab.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index 79d8c8bca4a4..97117a2fcf34 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -283,9 +283,11 @@ 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_create_args(#__struct, sizeof(struct __struct), \ + &(struct kmem_cache_args) { \ + .align = __alignof__(struct __struct), \ + }, (__flags)) /* * To whitelist a single field for copying to/from usercopy, use this From patchwork Thu Sep 5 07:56:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13791891 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 22139CD4F5B for ; Thu, 5 Sep 2024 07:57:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A72E36B0281; Thu, 5 Sep 2024 03:57:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A207B6B0283; Thu, 5 Sep 2024 03:57:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C1CC6B0284; Thu, 5 Sep 2024 03:57:50 -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 6CA676B0281 for ; Thu, 5 Sep 2024 03:57:50 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id DD33980F76 for ; Thu, 5 Sep 2024 07:57:49 +0000 (UTC) X-FDA: 82529930658.28.9F1B927 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf19.hostedemail.com (Postfix) with ESMTP id 2B1C01A0005 for ; Thu, 5 Sep 2024 07:57:48 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=IV4vVsui; spf=pass (imf19.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=1725522939; 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=78WvKHtyeiLYAwLH+95slKbH/rNgHFKK4/5wlAaE8fc=; b=5DR2Ismem+gaXiA4JStopL8rMzQehay634cJo4/YH1SSlD7bPhZqhYqBbNkrlAOV18INWW 7793gsKvp8zM5dOpqWqe8M4y/RANUPYOpaNM63eOD3/1yI44W7vmiWRG6S0kNrzyAOiToH X2UBqHUkQs7crlhlxg/rTyZs2cMgIlI= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=IV4vVsui; spf=pass (imf19.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725522939; a=rsa-sha256; cv=none; b=hbIt9gBEZ8rhQnQwIbmK9fq0cK7uqv+0cM3NsPMZU2//LfRYAl5EwqkUgC18jNNDAgbyFL PysMSu9tzKIGf5RNGovKaLsmgQBHJ2jzSsAy7K6JuBgPzeqtvHJYzhSitoRbkaqNXtkViP FXUAfYm86LAeptG4pdalxjwvx9Zt2X4= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id F367B5C3A53; Thu, 5 Sep 2024 07:57:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D250C4CECB; Thu, 5 Sep 2024 07:57:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725523067; bh=TRtSxtRqOM5QvqM+zpubd3lGKKoppNfgu7eGyWI4SSc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=IV4vVsuiF90rCnPrP9+D3fjrKdB7nkiU71sfUPuDqDHt7Nt84djcBwn0SvpdezNkT s8NRunt/BRsUKMWxfeqJdGZ5sAM/JrbGl0ilv7KFyPEyhaUi5sd5nRZ4cPW+cQJq73 JJkYqO2Mtk26MOvw28Lmx3oy5lZvOmIoJXIiEMF5tqIBS/DTl7f9F7xs6Z3We7/Upo D5loFUNGZEKdB5hKGPQnbYAUUhJXpd09ZCRWVf29oPY3USCLy09Cxm/mcjcHrbJ1fB O5KIxLW1Q0Djvh+7P7Aqw1aef+KotOa5TUewsPpw/5bgrWZoF0vpC5ZDwaPZXB/kG1 GYM2dMWIdk11Q== From: Christian Brauner Date: Thu, 05 Sep 2024 09:56:54 +0200 Subject: [PATCH v4 11/17] slab: port KMEM_CACHE_USERCOPY() to struct kmem_cache_args MIME-Version: 1.0 Message-Id: <20240905-work-kmem_cache_args-v4-11-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=1473; i=brauner@kernel.org; h=from:subject:message-id; bh=TRtSxtRqOM5QvqM+zpubd3lGKKoppNfgu7eGyWI4SSc=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaTdTPF+IvJk4uvP0VEreI5OXvLo5XUJHsXH71v3RZ+fs yVSb5OmSEcpC4MYF4OsmCKLQ7tJuNxynorNRpkaMHNYmUCGMHBxCsBE/PkYGV59mvLjgeraKQv/ f/+7OO7NgfUHju9nC2DMN3MzPGZndGIew/+UV9sDP31frXnR7BW7xOSZJduq1dj8zRNWWcZGH/6 fY8kPAA== X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 2B1C01A0005 X-Stat-Signature: 1dt7ax7dm8hdzu5986se84xg6he77q1a X-Rspam-User: X-HE-Tag: 1725523068-479878 X-HE-Meta: U2FsdGVkX1/6z12iichPE5Pb1qJMz1s4Xty8WbDX+4rrext6oat9ldqdYXRvHXRRTEFjXw80m4AVebB7eKun/sponPSIql2Fi9bO6tFd3KJudykvQSreYdFYLFK/cx4qv7BryBcT5sIibPcbXKGyaVRZmDc0/G58MjUiCOMIqqVipw1WgGjdtviFmqQeFaSVPR5gVrkauZPag6sDbBSP7R5pI135bratLfLzUd2wQoHHmAU3Hzlf705yF7XENg92ckyeZo8H3fY851M2u7KgSuHpXBBF9COLugbQ8ip66ZTSqkcGPFAZUIBQu+N1NxbapbJ+plfF5TFqU5mQwI5qQeD0vvjoFYJvAOhEU0QYoRXCP7ioeZQ7jQuzGRg/6VhcoIDe8GYV9xrSvgSJfOwJYF17jHwgBnztdxe3tETlNoLQggW2KVoN45UEvwYb0SieQk07bViMP+OD4lSmUSGddzwDKe95Dg0kzzBTdvL9vYLnUasH2D60EB38TeWfPBQNWii6t6ENG+Q5AqJ7cLthM5J6z+HYqgAxc5ulMjD2WEERh3da5ApKW/RpB+8N0ZmQAWwbK4CkE1pQ+pkXEc6QFTb01y0aQQvvrOFG4z9MzxQjKXjei0S34tf8qXE0KZ+gkGwxX7IzAOUJiG6B9y4CEs5TmYdJ3xJynqpRdVUjXsv+6BYOerpabb/oF7VfmQmVCID1O3xgANPuDpQDL3GviAe24DVv5V8iBZ4TdtCfbbDyFAmQAA1mYFZn9FUdevcjYdMDvX69L3bdD+dA4f9jQjxCHAYxdF/RUqAMPukOjSovvXhCrl5SYO5L+WleozMlHSe+goHpNDED+11vM9H0oFfjOHWfe7JZ0NIZgpZYb6g28d+Ee+RJ//nKEY57BYyn+lElhvefDzaC1qB6pPfZ9I5qRPwZImgwNo6Q4Gw0In0PuEBEeqa+uRrNz+dy+2Z8y/m5zaSlZUxfWGJrz96 /2gd4v9T CWbrPb7EMPZiV3c8AZrYB57f2Hnhk4uBS62U7irHr2XJ2iis+YRkEoo8/Vzk9JkjoSRCcJAF+0hRd87MUbIrZi0tsj+0eiwWPfXBeXz+PcfyvdKZtL9JYejagTQOseypgqlhW1ZtuRWDsr41HG38U/9Xkjce+zhvcXC+RNwKIVowxaD29nfFg4Z7nhow9E9e8V8lRodQSLgS3B98J2S7EfXiVbFEXHdBRhY9S9B+osDsx0TjGa2M/4MIZGSYv5CLy8jFWsM/dKC/kDgewdHez68shefzw2VsBh4Ffh50Pzc/zjWe8LQU9E4MjnSdPZ8XezSWgyDEaUbl5sV/OqAmCXsbt+1BOHte4o5DUZDO5EDfJDHAZ7Fzdx3uPSt2am3faH/53/0eSOlclqPg= 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 struct kmem_cache_args. 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 --- include/linux/slab.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index 97117a2fcf34..cb264dded324 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -293,12 +293,13 @@ int kmem_cache_shrink(struct kmem_cache *s); * 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_create_args(#__struct, sizeof(struct __struct), \ + &(struct kmem_cache_args) { \ + .align = __alignof__(struct __struct), \ + .useroffset = offsetof(struct __struct, __field), \ + .usersize = sizeof_field(struct __struct, __field), \ + }, (__flags)) /* * Common kmalloc functions provided by all allocators From patchwork Thu Sep 5 07:56:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13791892 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 CB1B4CD4F5E for ; Thu, 5 Sep 2024 07:57:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 542756B00FE; Thu, 5 Sep 2024 03:57:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F0CD6B0105; Thu, 5 Sep 2024 03:57:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 343DC6B00FF; Thu, 5 Sep 2024 03:57:54 -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 1466E6B00F3 for ; Thu, 5 Sep 2024 03:57:54 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C797581A2E for ; Thu, 5 Sep 2024 07:57:53 +0000 (UTC) X-FDA: 82529930826.14.8FD85F5 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf19.hostedemail.com (Postfix) with ESMTP id 135E81A000B for ; Thu, 5 Sep 2024 07:57:51 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=I7HvquUc; spf=pass (imf19.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=1725522974; 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=eMA77wqaMeZKMKqnOy472wO3XiINXeFs1N0hPm98s/g=; b=nR9RBvi1HvuJHVcGjB/r7qsTOEATB+7CfrLJMvvzJr7yseSdk7/9g8x2G6L+lZsDh0Fi7L uHwKrLhZMBfL7SBqAwA/1vn5TV81hNOuqbfwUxpCAFmtCXVsSNWBxYVUCrydXUaBQModTs 2TiMoSXKN4elYGXjUEvCnVZOiSngyhs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725522974; a=rsa-sha256; cv=none; b=zvP1GDDnMgcP0zOBmgVxOXanC2S50LSTyTlLi2mgJauL9QlNSslm4gcS8/CBTr4p8dxsIv lXUOyc94pKZyafG+NLlru3DXIFGBXW6XE6LNY4T4B21Vlq8lCSrOpPAaTypStAvcUFNRkk 8KpV2SPLVgahb4A8kGfhca4qPVPLsX4= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=I7HvquUc; spf=pass (imf19.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 37A07A44379; Thu, 5 Sep 2024 07:57:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0D83C4CEC9; Thu, 5 Sep 2024 07:57:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725523071; bh=xO3vcgDDnoCbF7ELZ5lnFORM5yLOC/pUkBkeRwkJlfs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=I7HvquUcEms6uaml8hK37xscwhQS72RhSKTnUPyh0vN66t2ZzapSWd1Gvi8uO6rhw umvVp1zmu8b5gVdoEmQ/RkZVPFUZFdUddhPh6Z/DD38rDAsP8xSVXqXx6ZTX1QkApz 89BQ+AZbPcJBU/XOw9PXkxOKGsgt/flpFUZvv+hJzOMDTzNxLwcjMGeBnU+fRS/+qG YGuLmL7irHDeC4iYwA9A8x36GNAJ7vj6gYJ3uhr6CIif750S1YMIKkrAzdal+WxfzE gA542w9e/qVTZIpPda7NJzSMIT52pzB4GuW4/Ijqve1H4S0Xg5R030ZVEkEuL8kt0h QZX8zNQI101Mw== From: Christian Brauner Date: Thu, 05 Sep 2024 09:56:55 +0200 Subject: [PATCH v4 12/17] slab: create kmem_cache_create() compatibility layer MIME-Version: 1.0 Message-Id: <20240905-work-kmem_cache_args-v4-12-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=3953; i=brauner@kernel.org; h=from:subject:message-id; bh=xO3vcgDDnoCbF7ELZ5lnFORM5yLOC/pUkBkeRwkJlfs=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaTdTPGWnv7hec00zY7uWcHZa36fWJ7VU33/TDKP6lqLz PW/14vGd5SyMIhxMciKKbI4tJuEyy3nqdhslKkBM4eVCWQIAxenAExk1kJGhmWHXumx3lsayv60 +XC6uci3R/ZlmQHCfw+In94cNDlrqxQjw/v1V2ZwbjStnHKhNWCVFYNj/4XntZ8kj/4XWR3ftMu pggcA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Stat-Signature: w7kdrq3bykakq1whmdjc8ao8tahxiobg X-Rspamd-Queue-Id: 135E81A000B X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1725523071-176697 X-HE-Meta: U2FsdGVkX18uiSxlzNb57TU0Jn5mln+bxAO0AOVw/zAjQ7T2MY24cIL5qLTWgx3LmG5pbpOkogvcSs9S8TChrWQFihNtlwO9EwTcg8rCZxvVP4rnNgGNDqibXhyuQK6s9Gii39hLtz83eq6JYWfcFPThwFp62z1lm4NGCYulkla2jdkITEnF00EbC/OLsg528R9diEKzzixA7CzfnFHDuysGLo0+oMGf0B0o0clJPu9LReppSCbOTln3R/Swa6lW4vyiAHQ0AXeGpJYq/ga/oWoQkWej3NSHYhaiE1/PotHIxBM7PVbZMMTXq99WNCAK3T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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(). If NULL is passed for the struct kmem_cache_args argument use default args making porting for callers that don't care about additional arguments easy. Reviewed-by: Kees Cook Reviewed-by: Jens Axboe Signed-off-by: Christian Brauner Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Roman Gushchin --- include/linux/slab.h | 29 ++++++++++++++++++++++++++--- mm/slab_common.c | 10 +++++----- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index cb264dded324..f74ceb788ac1 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,28 @@ 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); + +/* If NULL is passed for @args, use this variant with default arguments. */ +static inline struct kmem_cache * +__kmem_cache_default_args(const char *name, unsigned int size, + struct kmem_cache_args *args, + slab_flags_t flags) +{ + struct kmem_cache_args kmem_default_args = {}; + + /* Make sure we don't get passed garbage. */ + if (WARN_ON_ONCE(args)) + return NULL; + + return __kmem_cache_create_args(name, size, &kmem_default_args, flags); +} + +#define kmem_cache_create(__name, __object_size, __args, ...) \ + _Generic((__args), \ + struct kmem_cache_args *: __kmem_cache_create_args, \ + void *: __kmem_cache_default_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. From patchwork Thu Sep 5 07:56:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13791893 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 C953FCD4F5B for ; Thu, 5 Sep 2024 07:57:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F3936B02A9; Thu, 5 Sep 2024 03:57:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A2EC6B02AC; Thu, 5 Sep 2024 03:57:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 344236B02AE; Thu, 5 Sep 2024 03:57:58 -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 0A9E86B02A9 for ; Thu, 5 Sep 2024 03:57:58 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id BD5BC1A19EB for ; Thu, 5 Sep 2024 07:57:57 +0000 (UTC) X-FDA: 82529930994.29.4F91462 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf29.hostedemail.com (Postfix) with ESMTP id 0F3E4120006 for ; Thu, 5 Sep 2024 07:57:55 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=mYkXOr7x; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf29.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=1725522968; 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=QKJqJIYSilEM9Rvj2Blf0Qwwr2GZV8/aEuTuKNLevjE=; b=UP91xEZwB2U911rVfZfvZEKbcPkZLiggB/G7yx8mtgp0dd5BQtJlEabD35nHxcYY1prW3u 7rfbHIqlFSKcuEwasDtzibsROCD+4/GJDbL0Nc0voTGtNFzOP1LyGoaf0ch4p0kJyHJvqe ytLgl0Qxc7edTh4js4ZeHV50XET1Tb4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725522968; a=rsa-sha256; cv=none; b=KCy2uekYqvK4ULF5BB1h2Gx0fskyi/uezP2mutrurh07j99QRKvxm+64/h4vrpehHa6WzS au/Ds0AW2gki8+YFLhEV23qSJyLqV0NCxwg5hw7RZpkRbyWZYpD02UQOILllutO8JapvPy yz84eUj6lJ/lJhR2+y10fpz0DIrRztI= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=mYkXOr7x; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf29.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 369ABA44372; Thu, 5 Sep 2024 07:57:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B1F7C4AF09; Thu, 5 Sep 2024 07:57:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725523075; bh=i+qfsAgWogADWXKIX6Ox+SamBJe0NAxzXt2tozWQS4Y=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=mYkXOr7xS4Z4mkCbI0v9BXGFcdBL//failIOy4yeoCV0iFHDbwEGNpZ5lUT96/2rM FzuwjOabbXeq4zn+r6w1OuIBW8p/DnVBT7j6rukPS3OyCyC6AN3aWf49VSYSpI0VML 2UJwPFaz4/GJtXg4EXkPaof4zAh7spKsPz8nMcqahR/WVWwLm8l8FFx+JZP5Lh/HoQ 24x+U2rzZbmqfLeIKcCBfI3DZenROsICqGWZKO5nWoZIuP2vAt3nRO1ffbjo2ZXPYA MR/QICqC6xGnAAmxZyKiOcMTZ+C0BBDqJXU9I69e63Eh/30cpfHZvxcjNz43rgheQ3 CgE25VlJ6vPAQ== From: Christian Brauner Date: Thu, 05 Sep 2024 09:56:56 +0200 Subject: [PATCH v4 13/17] file: port to struct kmem_cache_args MIME-Version: 1.0 Message-Id: <20240905-work-kmem_cache_args-v4-13-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=1128; i=brauner@kernel.org; h=from:subject:message-id; bh=i+qfsAgWogADWXKIX6Ox+SamBJe0NAxzXt2tozWQS4Y=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaTdTPFeMkFxdeKVKz5uTZv//oozC6j/eSV1QtD8yNSbF 3dazFPS6ihlYRDjYpAVU2RxaDcJl1vOU7HZKFMDZg4rE8gQBi5OAZiIawrDPzX+vdEdqptkD+78 32r3fWVw3YzH7oZLj54zjVh1yzvumwnDP+UO2TWtxg38Rrvuz43yCxZ9w/I3XOsE35Oppb7yIhl /+QE= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 0F3E4120006 X-Stat-Signature: m14rnbm7xquz873p5w7jenuqzq3bg7du X-Rspam-User: X-HE-Tag: 1725523075-979954 X-HE-Meta: U2FsdGVkX19SJNiZl1Q4ZISFbqXq2pS+b/2rf2RjyLSILxiOYcpe87qnvuxp0FWKiJrfaHj5tM1kZ5ZUloqWBMcrROazfHpxSoR8GEj53mcOsKcNd9tA+IYWulMVWSeKk1Qg6omEC4eQ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dIlHBDupk6aqh9Aa+QtouHO51ZEDZqAHDH15ByifR61IU1UvzF4vXPQqtjIIYZjAH1arVgcj4eNlWMiYjxSw81lcJEI3YteSZi1ZBMYqjX8X7DbBd5LWiiDrg7/jTY6a9dPi27K6wIkBkflXCyvFujrFWPne6iG3UUlO7M= 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: Port filp_cache to struct kmem_cache_args. 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 --- fs/file_table.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fs/file_table.c b/fs/file_table.c index 3ef558f27a1c..861c03608e83 100644 --- a/fs/file_table.c +++ b/fs/file_table.c @@ -511,9 +511,14 @@ 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); + struct kmem_cache_args args = { + .use_freeptr_offset = true, + .freeptr_offset = offsetof(struct file, f_freeptr), + }; + + filp_cachep = kmem_cache_create("filp", sizeof(struct file), &args, + SLAB_HWCACHE_ALIGN | SLAB_PANIC | + SLAB_ACCOUNT | SLAB_TYPESAFE_BY_RCU); percpu_counter_init(&nr_files, 0, GFP_KERNEL); } From patchwork Thu Sep 5 07:56:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13791894 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 DC088CD4F5B for ; Thu, 5 Sep 2024 07:58:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7164B6B010A; Thu, 5 Sep 2024 03:58:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6A2986B010B; Thu, 5 Sep 2024 03:58:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 283986B010C; Thu, 5 Sep 2024 03:58:02 -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 093E96B010A for ; Thu, 5 Sep 2024 03:58:02 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id CBF06AB0A9 for ; Thu, 5 Sep 2024 07:58:01 +0000 (UTC) X-FDA: 82529931162.09.2CCED9C Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf23.hostedemail.com (Postfix) with ESMTP id 27609140013 for ; Thu, 5 Sep 2024 07:57:59 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Cm9Sd2Di; spf=pass (imf23.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=1725522984; 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=+TLzy+xdOwmwHtnmkVNYR0Tbt1erdt/6SiK9MLuoqrs=; b=0Sjuq12hIirrZP1bmmNHUZpzrEHd5fdYT7WiqSAfYaxNBtCiVCqa/DraI7r/9bPGISINdP h2T7xVcetOp5EeU1otJ43V5N5WSiZHPT4rqhKi6q5kZsMf1MPFWzVX6Jkg5yGDvAvF5PSj X/D2/WtU5QyjNQoKknY62LBqxWHUchs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725522984; a=rsa-sha256; cv=none; b=GwrCM1SseJy/MOzun6LwfAb6YK/OZjgVphOIBCyewj+316+fsHSA1fhkQq2WfzAgPwMKQx a2AUL7eIwtRtbyE8g8jc9DigsNfrbUmYI4Rt6Nozudr5NNppSmP1jKFNkIuPfY/GfGievg rUrh6h4/z2xdqA9NlCFgyPob2+P40Hc= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Cm9Sd2Di; spf=pass (imf23.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 35E96A44378; Thu, 5 Sep 2024 07:57:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9920BC4CEC4; Thu, 5 Sep 2024 07:57:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725523079; bh=c9WyXR3UutI5YuOZDzru6g9A7doJ0To6Z/yCENECssA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Cm9Sd2DiCmnN0M4VfGZk7Ktm5XhL7pstZXSAV2/tXTU0vjUTxs17RLf9hjLGtOvjr aJuzjiNbaXAw0LLzOGR4Kkckwn0fnE09r3ZmDZ/kHmLqzpeCr1buh5ukhX4ArhnWrg PUQIGMuRq8rnFXLrp2CEa8HmM52xfYv66EJKiCyh1q3wy8/FOiQXi7vs9Tah2zsODe CosxMcX8TUjUa8lTOHalsD5psOIeXV3QgYlKjByOBrBU7LF4R/gPR00gARG+pwrohn DDHKwylYuoaxckibZsHQvhMGDCp7+cnBl1N65RZblKCkMhS8juxVlCdR9cqGkOs/5Y AZuImLS0sp9dg== From: Christian Brauner Date: Thu, 05 Sep 2024 09:56:57 +0200 Subject: [PATCH v4 14/17] slab: remove kmem_cache_create_rcu() MIME-Version: 1.0 Message-Id: <20240905-work-kmem_cache_args-v4-14-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=3200; i=brauner@kernel.org; h=from:subject:message-id; bh=c9WyXR3UutI5YuOZDzru6g9A7doJ0To6Z/yCENECssA=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaTdTPG+F8+58dldnj9qzNtvnnm8aYfemt7vfz66bb2oG iHMce3Hwo5SFgYxLgZZMUUWh3aTcLnlPBWbjTI1YOawMoEMYeDiFICJxGsy/M/5INce7OTJUvjF Z33SiZQN9YV1DbtmHLIulz2wyily3XOGf/aFNUbt6q4vZqyd+vP26xvmEqsurtf8Lms8z/OtwNX yg+wA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Rspamd-Queue-Id: 27609140013 X-Stat-Signature: rffssg9iuj6xzi596343ks4uexu4a9ye X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1725523079-376619 X-HE-Meta: U2FsdGVkX1+bbQ/DkpbfW/G8RIEVfHD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Ao8VQVI2x+oNcpjzjIw7qNrmCBfv8o0HolyAdNbhjqsIDFVqTRRAn+GsqvQxqiXEEamdrbSQuodabKjfu8Jn4T6KsBRE0AMgH4+S6YX8OPOiLkeTroMMGwPf/NOd90Wu6iT+n+hAYRksQXQvhDAhVPGBPsk5xnmOeALGcMyInjEElz1iMUtS91Why9L/HT7oL4IU4NNxsRW0CcVreoq496IslSiB1J3Xxs47f8r9NwDrunHXDP7AdbNJLxiMQqbY+RP/vfghxAHigiup+ei1GJVjM= 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: Now that we have ported all users of kmem_cache_create_rcu() to struct kmem_cache_args the function is unused and can be removed. 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 --- include/linux/slab.h | 3 --- mm/slab_common.c | 43 ------------------------------------------- 2 files changed, 46 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index f74ceb788ac1..8246f9b28f43 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -270,9 +270,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); /* 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 418459927670..9133b9fafcb1 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -420,49 +420,6 @@ struct kmem_cache *__kmem_cache_create(const char *name, unsigned int size, } 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) -{ - struct kmem_cache_args kmem_args = { - .freeptr_offset = freeptr_offset, - .use_freeptr_offset = true, - }; - - return __kmem_cache_create_args(name, size, &kmem_args, - flags | SLAB_TYPESAFE_BY_RCU); -} -EXPORT_SYMBOL(kmem_cache_create_rcu); - static struct kmem_cache *kmem_buckets_cache __ro_after_init; /** 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+6eZQPKNlRllLgUwcSndAgvCaMI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iEUzvHgh/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. From patchwork Thu Sep 5 07:56:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13791896 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 C2D5ECD4F5B for ; Thu, 5 Sep 2024 07:58:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F2DF6B0126; Thu, 5 Sep 2024 03:58:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A44D6B0127; Thu, 5 Sep 2024 03:58:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 31E546B02BE; Thu, 5 Sep 2024 03:58:10 -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 132516B0126 for ; Thu, 5 Sep 2024 03:58:10 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C7AFD40A4B for ; Thu, 5 Sep 2024 07:58:09 +0000 (UTC) X-FDA: 82529931498.08.623E98E Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf09.hostedemail.com (Postfix) with ESMTP id F2CB2140005 for ; Thu, 5 Sep 2024 07:58:07 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=UqxXrGSk; spf=pass (imf09.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=1725522991; 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=q+WhBmSfBnW7XNOC0hG1IUMxGBPMKlAyI6vX+m1inqQ=; b=K/rZdU4spTyG4wtQboVifwEM3GfJYBzkhdDlF3NS/On6Toh67f1KFJPFBao0Vy/WpAfWRe 6TLbN6Xbieh3yxn4iaG4WK+gLrDCeUUjhXfAHFY66I2cRUfq06TjinfvTPIQbrK6DrTZAT 20OR7Hq1NGbACPyMoYbWG/NoLiDsD0c= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725522991; a=rsa-sha256; cv=none; b=YpohcdWEM0xNFjnUcWFhD4XtwM8BDpzc/PzuH6idh7fHFfpWp2NdwyGoMz6F0D/3QTKprr 10jHowtoqN7Qp56ljGMMsbIgOBZyOPfn7iXCZT1G478umEdmu1snGz2CZDc9QQUIJBiloT BfYm1B//KN0c9ec+avbCYyFwlKJn1uw= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=UqxXrGSk; spf=pass (imf09.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 B8BA75C0FFA; Thu, 5 Sep 2024 07:58:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F903C4CEC9; Thu, 5 Sep 2024 07:58:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725523086; bh=rwJKoUBiD4opsF3q3lc+9pnVXWY01qThhoh7PngENwk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=UqxXrGSksmpwRA6ISWIfcsy2RBc0SFe/JRNtZg49zhcODYuHDz3xFWj156OUJxLZ+ wlgA48rZ4aVjDeDgAisVGRtKKDZSAUgVWYuH02G8IAvR1flVT5sBrD/kRxow7t9U/b avyDBgagBqJmDSz3qCSe51VQ7h6c2PS6AnttGq5P2P8rnS3PPs8BJMOKtM7B0O91yS TrSImZBnPOaVASgyaAjqy93Uugn9w9qq7b1L9P0Er6SKg16c3pVSoYGQMouoQRQjrO 0FMi80Rd1VmLqkkLYKgzSdFQJeQW52mEZPHMSWtDuXWaiDK9hDfmx/JgEGNqxTI1tB U71j7fw3uPvdg== From: Christian Brauner Date: Thu, 05 Sep 2024 09:56:59 +0200 Subject: [PATCH v4 16/17] slab: make __kmem_cache_create() static inline MIME-Version: 1.0 Message-Id: <20240905-work-kmem_cache_args-v4-16-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=2885; i=brauner@kernel.org; h=from:subject:message-id; bh=rwJKoUBiD4opsF3q3lc+9pnVXWY01qThhoh7PngENwk=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaTdTPEuPu2j8kRPI0DSfXdC71rLqwZ7b+4XeG9n8f8WI 9OWKwblHaUsDGJcDLJiiiwO7Sbhcst5KjYbZWrAzGFlAhnCwMUpABMRyWf4K+S264SiRNnN4pCy otf59c/vPTdSWrb90XZ2I713D2RXZjIyzJ4mt6dx8kq790bb0i95+X2PfXjqj82S4I29cxZ9uaN 6mhsA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: F2CB2140005 X-Stat-Signature: 7tor5cs5bxq7fjb61aqzudq6qjc7e8bw X-HE-Tag: 1725523087-81856 X-HE-Meta: U2FsdGVkX18ofUNh4YG3qh0Hj6nXgL5/J0irLECXF9nXUNURxrY2CapAUuiZ+ZHu9lCpMw6xajcVk1sbvIPKmKed+1pcoOiHN4BRh8lsQJkg/vvztOCkqT3ZIuyFFOm5vHnbsCPMN9yJS4LU5zNazqkNB3k0eNWdJ0LIlyxIhaSUx8pfJJjut4bb7B4Hx8jzwqeaOzooXsH+Xus0CnUvKwUu3YLDzTkFKK5r0v6+uTw2kGkCXc5T/NGzfjtkgnLY/WD2jighacTdPF/qT1lBi/ikBS8lRzbrMLucCmGlFUdfzYP/aQ3RAqNYyQrJlqB59OxsjrnNPmigAce/jAJ6r1E8oXekdUVF7VNBMoH78SFPdTOeknTXGs72v9j8V/Yfkj7WWlaqlWj+ffE6iSoXH/ObOzuqDuJMItuI9QbCiOuNInZkWRnLaubrG1jMwy15gq0E7v/FU0A+dnCawx1i82TgeTNS0FH/98QAp77fkZeF5m6hAIJqU+UK8ABM+OsVx/naUeAjjVpWeuVk53mcmJUl9dHebRPEKIuu9arScwy++yjeZ6n98W8rAh2kNyUIbq1Lt8pAumWG+3zKZCovNa3nenkTnQtPrEoLjUnZorbJ8nwDaW11OIOcPEcC8yMMp+BwmjugBUb4jc+Ezb7kUdmkMH01Nep5ydNStASzefWnEaRllVzLGEkmR82UxHG5HUj5l5DnIYvg7/2elP3aEHnXHg1J36lWuGxTsXrBOYB3nKKiRbcfN5V0ucolv6CufIFS/oLXdDpWbLWWSloK7T3l3hX4aLN9Fo/r+iOWaslIfRRKrmJdVxHNMff3jJ3lKMtOTYdxXq76+C+KsXG3M2WRqt+gCYuAOrwvHiGnLJgqRF2fHC0D/fd3m1s1Rm0cGWLqKcnc6hE5XJw0eE98smSnIxwRuUZn1NdYAYUV2DZROXJlScyxcsfmrYTbeLl9q1QXq2hCkOkDy7PT6C3 5wsbp+dX /d3e1BvuIKdBK/RygJ/Dqpne3gMxFXv50fyH9GSdH8DP4mPzH20YUmKBQJUrVdCv4aTWSjfK7mx7s3uUvtk+mYg6GQNX2reYOy56OCJZcwGuYqMLUzJI92XsRGJV6nS/74kWCAUPwJ9LlwYuu6Qhny7ewMhmtdEUtJqLxE8MUF0/LeszQoC47zbGRN1EkmulJTb3h1S6Dl41XmxC/NgetaAYl39PjcbuuzPzUYhN4Lz4EFTVaRLGfjYSqGiezF83/yViEWqkeEJPx83uQVd1SK22c3BF8YrEpvhIs0y7+4EWd0Zj0Ew4GWnt58KaYEh4XzylK6If857wJFE5y3xsuiVwdTzGmfcpCO2wTz9BiCYhjE9QRL4mN6UUsMA== 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() a static inline function. Signed-off-by: Christian Brauner Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Roman Gushchin --- include/linux/slab.h | 13 ++++++++++--- mm/slab_common.c | 38 -------------------------------------- 2 files changed, 10 insertions(+), 41 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index d744397aa46f..597f6913cc0f 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -261,10 +261,17 @@ struct kmem_cache *__kmem_cache_create_args(const char *name, unsigned int object_size, struct kmem_cache_args *args, slab_flags_t flags); +static inline 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, + .ctor = ctor, + }; -struct kmem_cache *__kmem_cache_create(const char *name, unsigned int size, - unsigned int align, slab_flags_t flags, - void (*ctor)(void *)); + return __kmem_cache_create_args(name, size, &kmem_args, flags); +} /** * kmem_cache_create_usercopy - Create a cache with a region suitable diff --git a/mm/slab_common.c b/mm/slab_common.c index 3477a3918afd..30000dcf0736 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -337,44 +337,6 @@ struct kmem_cache *__kmem_cache_create_args(const char *name, } EXPORT_SYMBOL(__kmem_cache_create_args); -/** - * __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. - * @flags: SLAB flags - * @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(const char *name, unsigned int size, - unsigned int align, slab_flags_t flags, - void (*ctor)(void *)) -{ - struct kmem_cache_args kmem_args = { - .align = align, - .ctor = ctor, - }; - - return __kmem_cache_create_args(name, size, &kmem_args, flags); -} -EXPORT_SYMBOL(__kmem_cache_create); - static struct kmem_cache *kmem_buckets_cache __ro_after_init; /** From patchwork Thu Sep 5 07:57:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13791897 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 AE55FCD4F59 for ; Thu, 5 Sep 2024 07:58:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3BB466B009A; Thu, 5 Sep 2024 03:58:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3431C6B00CA; Thu, 5 Sep 2024 03:58:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E4E56B00C7; Thu, 5 Sep 2024 03:58:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id ED0166B02C2 for ; Thu, 5 Sep 2024 03:58:13 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A22351219C5 for ; Thu, 5 Sep 2024 07:58:13 +0000 (UTC) X-FDA: 82529931666.29.03120B8 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf29.hostedemail.com (Postfix) with ESMTP id C854012001D for ; Thu, 5 Sep 2024 07:58:11 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="n/cii1Y9"; spf=pass (imf29.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=1725523015; 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=LmUvlQw/XUOFJDyv2fVCf9l2Lda32tanKJIv9PQ6SeI=; b=xkE6W8AQe/BqxECqvcKvfgVfAiASdaRc8l2Le+y4tJJDvBIKPyX8P2Yw3Kj280e35ONZO4 hOrTVhJPLsNAR/2a04oJqTpdbBfOQs/xEViJP+OY8mxDVFhkReD4bbZ6+vSxIr/lTyHf47 TDEyb/Ro6YO0WameI9lh+34/IECDEpc= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="n/cii1Y9"; spf=pass (imf29.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725523015; a=rsa-sha256; cv=none; b=Pdd2pNSgtvnFzh82zgOLV6YsU5Z5DB+gPOdH9ul2JS3bageqagk7FoM0NMf/5VSJCzjfBv z5UuY5/KNbgSKxjyBp66jaIC36klk65607A/l2eYOxe3URDoWNYFIuvgUFNpMwbblWut3V EyRo58u0QTq2NaaDAtYnr27b4HVpwAY= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 8B5BB5C433F; Thu, 5 Sep 2024 07:58:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6815AC4CEC3; Thu, 5 Sep 2024 07:58:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725523090; bh=EjTjGH3N7I+He4i3zTdEnIsNUEnQ9qSuzD1HUDVnA88=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=n/cii1Y9UaMO6oLLzq+PA4Vy0/MwZIQeJ9yLODD3MvOMqqhPRxWm1x7GIX25GI/qp G690aWfdS5p10x5FCW5PqvhbTqhZefA0icmgivaU150EthEStFU1AgYtFd3GeaOJQy U4EScFhr20WPqHmcHBwGz1opcb326Vs6aCqxqTaMdv5qaB+uU16A1bpHtGHEOJoNG8 cG/Y6jAnwZWHfrKLMKWP4gsjwHZdhNZHV1UgcQkVza8kALbZknFpAhxn9Vbp65HgHn YDHbbJ5pm08OwI8mAypTWkqRLG7PQy+k8l1qGm1E1kBRtOq1owOgJziQNM69rdMVQo PdkjcvlwIrOyg== From: Christian Brauner Date: Thu, 05 Sep 2024 09:57:00 +0200 Subject: [PATCH v4 17/17] io_uring: port to struct kmem_cache_args MIME-Version: 1.0 Message-Id: <20240905-work-kmem_cache_args-v4-17-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=1730; i=brauner@kernel.org; h=from:subject:message-id; bh=EjTjGH3N7I+He4i3zTdEnIsNUEnQ9qSuzD1HUDVnA88=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaTdTPHhj1L7r/Bk2qwz7j/NNA3ZPkds8Gb9+f4l61uHu nD93VXpHaUsDGJcDLJiiiwO7Sbhcst5KjYbZWrAzGFlAhnCwMUpABPxOc/wV4Cf57l0b/FcH1+T VFkn/6fcDXo3btpERvZv8f637gjjBob/SW8yPtZ1fvr0p+QH91+O+GOvnQR7eBceb745USDVSoK VDQA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Stat-Signature: dgqgzbm8zb58itxorr537mqrtnyx5yyg X-Rspam-User: X-Rspamd-Queue-Id: C854012001D X-Rspamd-Server: rspam02 X-HE-Tag: 1725523091-94400 X-HE-Meta: U2FsdGVkX1+XY4+epcNN2AwZCyLzArse6mlk4apTnl9XKo4bZ1xCyRavgkr8hKgrpNNdiarAO9SlkANjxauiphVxIr3rmqGKVdgc8zf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JL/3Au2BxdpyMmG2FF4OCK+OXWHJg3YcWXRIAt3Vatu9kP4qTLIT364VfnQ5fzPc6oWlo3iQ91UEcRlEz890zrDSnB9iRtHuHjLOtVj/f2nDqQ4ROlNMDkXHkjNu7i/gb0CMmxrnKML8l4AFSz/Z5DtCxsztSe3qJtJKXa/MjCbYp1K4eCd4N8WjOr1WVaROaulJC1HT/IccqrsrOh969u81xilMAfRmhR 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: Port req_cachep to struct kmem_cache_args. Reviewed-by: Kees Cook Reviewed-by: Jens Axboe Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Vlastimil Babka Signed-off-by: Christian Brauner --- io_uring/io_uring.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 3942db160f18..d9d721d1424e 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -3638,6 +3638,11 @@ SYSCALL_DEFINE2(io_uring_setup, u32, entries, static int __init io_uring_init(void) { + struct kmem_cache_args kmem_args = { + .useroffset = offsetof(struct io_kiocb, cmd.data), + .usersize = sizeof_field(struct io_kiocb, cmd.data), + }; + #define __BUILD_BUG_VERIFY_OFFSET_SIZE(stype, eoffset, esize, ename) do { \ BUILD_BUG_ON(offsetof(stype, ename) != eoffset); \ BUILD_BUG_ON(sizeof_field(stype, ename) != esize); \ @@ -3722,12 +3727,9 @@ 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_create("io_kiocb", sizeof(struct io_kiocb), &kmem_args, + 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);