From mboxrd@z Thu Jan 1 00:00:00 1970 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 E4A6CCD4F21 for ; Wed, 4 Sep 2024 18:21:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 35D9D6B0150; Wed, 4 Sep 2024 14:21:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 30F2B6B0463; Wed, 4 Sep 2024 14:21:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1D77B6B0464; Wed, 4 Sep 2024 14:21:21 -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 EFD786B0150 for ; Wed, 4 Sep 2024 14:21:20 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 8BBFF1A0287 for ; Wed, 4 Sep 2024 18:21:20 +0000 (UTC) X-FDA: 82527873120.10.4ECD25B Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf19.hostedemail.com (Postfix) with ESMTP id DE9861A0007 for ; Wed, 4 Sep 2024 18:21:18 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=I1VJst9y; 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=1725473983; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Ke5k/kz78tjIs859vIPYcCNjSZDvQ7NBDCwrPFZunXE=; b=hH/nCs/yqQp12rffCnxoGvnPCiGNJo/Pye7hLRb4mVM0pkgSpbO7C8tr5KS2o/f00w/ahJ elIkvWl27UgBS1oKuiVCgpQPUyov4UD2qQp31X3xSEqeX6uCzgWbNLgjwYO0uW6LM30cQN cK3KHXJwrfCU0r8M5eqzdiuxNyDSIyQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725473983; a=rsa-sha256; cv=none; b=xZ4JVSes/vCJGwVt0HIPqSN0MKsgM91eo4f6n6rXBnIwjifzOL7efHVGGQs7Wfn3ZlHe0A keyqs24Mva99wVueJmlW6J9YRWuPsJQ0aLbhwJtI6GQ5VMgXKehCYCwB060dZGcfyHYSCl ztDGOqlrQdViaDH33bMu/Ey/3Df3SLc= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=I1VJst9y; 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 D15CEA445EC; Wed, 4 Sep 2024 18:21:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F30A6C4CEC2; Wed, 4 Sep 2024 18:21:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725474077; bh=V1uKUFVLNzDRxnwoyhKTpWj6r8IKWS9JkIbr4UGgtn8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=I1VJst9y+dSonlwue5C7bteIVSPpGPZFpzqx/T0ieIu0KXzmEDLBFNsEpNm5EUQ7K 18x3CVnP+KCrnc+QAoJ+WaQ8KVxtSB+uC5XOTUSI58ZqiNJVxYJRaoXE8+KrJJInMB aeSz8Dhx7592scQxnLJAdRs//vFIfX/wIrD/LEsxBBFYAbRkQwxpeYxLNW8uE9AfGo /1YXSiNcV71d7ahbKQdKzr5M69qLwlPjcgmiFF88bY7IKhiOgWMTgIWdHLFuuUScoj RP7Ebse2FcunwZ5dBobYFV2UBz14KbDHcayYnJ285Ux+M3/Qq2D4HwlCCuqaC7mtl9 fN+ku2dCTv6Aw== Date: Wed, 4 Sep 2024 20:21:13 +0200 From: Christian Brauner To: Vlastimil Babka Cc: Mike Rapoport , Jens Axboe , Jann Horn , Linus Torvalds , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH v2 02/15] slab: add struct kmem_cache_args Message-ID: <20240904-kauffreudig-bauch-c2890b265e7e@brauner> References: <20240903-work-kmem_cache_args-v2-0-76f97e9a4560@kernel.org> <20240903-work-kmem_cache_args-v2-2-76f97e9a4560@kernel.org> <9303896a-e3c8-4dc3-926b-c7e8fc75cf6b@suse.cz> <3ade6827-701d-4b50-b9bd-96c60ba38658@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <3ade6827-701d-4b50-b9bd-96c60ba38658@suse.cz> X-Rspamd-Queue-Id: DE9861A0007 X-Stat-Signature: 7h19itrodcirawc9u8atmdmfsdashbow X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1725474078-422044 X-HE-Meta: U2FsdGVkX1+zd6azmySMwOv78wDdjIPQ4108YPNXmdNRoKiCPZ15ZkY6gCCg2cT4pMMjczxJ/JZlJUPEwjObVg0uD27U76DUj/Mft5D54aILCWA+y5qazJTOKYZn6P/Pe4zyewO6mocfx8KYTZIuNQslA7WC8TmuWEiRl5FpV5+SCvlvPddMNz5BFU/2ofgvm6UazAaSB+Sr9S/d1HGzwz4dRGEnNJ6lbi/d1EthixxlKfS99Xz6wVl7EHusmhEYCe/bEZXsIom6ao783Kt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osity: 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: On Wed, Sep 04, 2024 at 06:22:45PM GMT, Vlastimil Babka wrote: > On 9/4/24 18:16, Mike Rapoport wrote: > > On Wed, Sep 04, 2024 at 05:49:15PM +0200, Vlastimil Babka wrote: > >> On 9/4/24 17:16, Mike Rapoport wrote: > >> > On Tue, Sep 03, 2024 at 04:20:43PM +0200, Christian Brauner wrote: > >> >> @@ -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); > >> > > >> > Sorry I missed it in the previous review, but nothing guaranties that > >> > nobody will call kmem_cache_create_args with args != NULL. > >> > > >> > I think there should be a check for args != NULL and a substitution of args > >> > with defaults if it actually was NULL. > >> > >> Hm there might be a bigger problem with this? If we wanted to do a > >> (non-flag-day) conversion to the new kmem_cache_create() for some callers > >> that need none of the extra args, passing NULL wouldn't work for the > >> _Generic((__args) looking for "struct kmem_cache_args *" as NULL is not of > >> that type, right? > >> > >> I tried and it really errors out. > > > > How about > > > > #define kmem_cache_create(__name, __object_size, __args, ...) \ > > _Generic((__args), \ > > struct kmem_cache_args *: __kmem_cache_create_args, \ > > void *: __kmem_cache_create_args, \ > > default: __kmem_cache_create)(__name, __object_size, __args, __VA_ARGS__) > > Seems to work. I'd agree with the "if NULL, use a static default" direction > then. It just seems like a more user-friendly API to me. Sure. So can you fold your suggestion above and the small diff below into the translation layer patch? diff --git a/mm/slab_common.c b/mm/slab_common.c index 30000dcf0736..3c12d87825e3 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -255,9 +255,14 @@ struct kmem_cache *__kmem_cache_create_args(const char *name, slab_flags_t flags) { struct kmem_cache *s = NULL; + struct kmem_cache_args kmem_args = {}; const char *cache_name; int err; + /* If no custom arguments are requested just assume the default values. */ + if (!args) + args = &kmem_args; + #ifdef CONFIG_SLUB_DEBUG /* * If no slab_debug was enabled globally, the static key is not yet