Received: by 2002:a05:6500:2018:b0:1fb:9675:f89d with SMTP id t24csp576450lqh; Fri, 31 May 2024 09:43:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUMk7etIr62BI/QpPK55KT8LxYxx6F4LM9btQzwYnzkvjGKEaMeSyz9FZiv4stvEaCZlmNh8lZYETCwBcPnkjBswMNRUUOtparLTacGTQ== X-Google-Smtp-Source: AGHT+IHfoMj1PNMHWVGg7VK17/VL/ZY+yArzHdYCKhp8hhTNk+gNYwX0kCjMFwESiLMyXJ/rdT0+ X-Received: by 2002:a05:622a:199e:b0:43b:e48:6512 with SMTP id d75a77b69052e-43ff54b0132mr25222331cf.45.1717173820936; Fri, 31 May 2024 09:43:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717173820; cv=pass; d=google.com; s=arc-20160816; b=mR9Wwb8BVRHDVNA3io1/jitFzsb8t8AGwydAycotCpzj9S9dLN5aWEFCnwG2meuC4+ hqTHSH2uchgiKQYriTjJGXuOyqIPrWLddvtvRZD2lFynaoO0ml0O7A9wYlFGO5Tncj7r kWd2TAt5M4q+10Ke6qb9/MT5CFwAB4g7iCpAjxmnkL6jjlcKXWn25FqvV5/g340s5gGg FPnGWxuve31P22fVknJsEcDPl7iiKI/QCwuEfZGd94nvTh2aGOXVYxs36hDvJmSOR51p Y6vmdfkTb9cy191HNi6F6uektRPB1e/osUoinv0xD6IDjRzIj+Y/BEYzhQ+xP0a+kIUT l6xQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Saeq2k+NPAJztkBrMiqKdztf8Mmi6wxGgMz+6zbFdq0=; fh=836k62dRAWmEUQHyhPvC1zBGQGlTdImsyVYtupo2ero=; b=IbDyVcDczVOE+89GXYTTlZjj5jTCbI3iPylGxl6jxFSP5vX8ndcEthn5hq01UrYjxG g76rxVPx6Cwa57zTpvd9qnCRWhO9Mv9LAPLceRfaxTR8959uFRRJqFv8DnOLRftc+ktb dRP2e+dZitVPztxTNu+Wh6bv9wN9DEmx3JafH6UMmvkIJUwkJXL8aEgesKEr4GNwDgMV j7zktBg+21WmhVGhpEArfcBjx/tncGvFRuuiVsVu9iiadIqegPXuZwunzjl3Br/mXXP4 Q/JaGc3Ok6t3LwmZ6VsKJJ05KmMiV03NWVwsRA8pCZqXmbDIhKCrt/PJFTzT3VAtKojq nqAQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LJxSOJZz; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-197174-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197174-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43ff2466a2asi11270621cf.277.2024.05.31.09.43.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 09:43:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-197174-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LJxSOJZz; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-197174-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197174-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 56FF71C21136 for ; Fri, 31 May 2024 16:43:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A56BA16936F; Fri, 31 May 2024 16:43:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LJxSOJZz" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA8E9612EB; Fri, 31 May 2024 16:43:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717173780; cv=none; b=MSVgTmyRZkmpPGKI47Keq+FbFUGzfc1Q12djRW/HtQIOw9RLry5CEpb8MKGyQIJvA4d7t3zegeQuMK2n3qunVmszVBSaxMt5gVVFeoWLAl4/bhfBCuHP6NphrcbVJzXgdsCLeg+v0jLCLf6kBKDh3+QG/qAMVWVeL+TAsHx//6M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717173780; c=relaxed/simple; bh=h9xEb88Q0BWA/HKbvxBqBPuQDNJV6+lkfys9wgwSsd4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JI6ibIydSleSqNxCMu9ioRxtbCijpnEwy0VbfjB/QNiq12IwY1GpVSH8lnJgr1457K2FerTJnRaI1Bj7WezV+7NE5aabU6rihkBITb+dqMH3jXreaYa5qjer94bRg+BoxjDTIXO/GwCYFKk7MmwibpoWrCklelRTBUoGzFnBAd0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LJxSOJZz; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59C18C116B1; Fri, 31 May 2024 16:43:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717173780; bh=h9xEb88Q0BWA/HKbvxBqBPuQDNJV6+lkfys9wgwSsd4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=LJxSOJZzlU7TkY1lfyEgw7d4dSBX70y+IdQxau1AYjYqMhq3n9Aeng0lWxYyrMfVm WvX1s1qSiNqT5sxYn/WmHZCV7Wxs7AIvQGQt4zHIWEYv5cQAQF5dmiBHx/ibv864wu 6LPZGsE3A6AaH2lXyQBmfa49XHreH6tvw8cCnrdQQz03L8W9wCbMUEqRdzqD6bOr1T 4SiriN9dvIFHLtb+5WRrARo0pKcQ7IZYGS1mTF5TnZ/85a/dJ4Gay/dFALwYogYo0Z urv031NJ5vNmqL3OhGq4RKc27FvzzG2gwO8ZuRkQ3mQU4ilHrFQq8C8WbN3TmkQdY4 sRB6tfzzLGwug== Date: Fri, 31 May 2024 09:42:59 -0700 From: Kees Cook To: Vlastimil Babka Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org, linux-hardening@vger.kernel.org, "GONG, Ruiqi" , Xiu Jianfeng , Suren Baghdasaryan , Kent Overstreet , Jann Horn , Matteo Rizzo , Thomas Graf , Herbert Xu , julien.voisin@dustri.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 2/6] mm/slab: Plumb kmem_buckets into __do_kmalloc_node() Message-ID: <202405310941.62F7B2859C@keescook> References: <20240424213019.make.366-kees@kernel.org> <20240424214104.3248214-2-keescook@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Fri, May 24, 2024 at 03:38:58PM +0200, Vlastimil Babka wrote: > On 4/24/24 11:40 PM, Kees Cook wrote: > > To be able to choose which buckets to allocate from, make the buckets > > available to the lower level kmalloc interfaces by adding them as the > > first argument. Where the bucket is not available, pass NULL, which means > > "use the default system kmalloc bucket set" (the prior existing behavior), > > as implemented in kmalloc_slab(). > > > > Signed-off-by: Kees Cook > > --- > > Cc: Vlastimil Babka > > Cc: Christoph Lameter > > Cc: Pekka Enberg > > Cc: David Rientjes > > Cc: Joonsoo Kim > > Cc: Andrew Morton > > Cc: Roman Gushchin > > Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com> > > Cc: linux-mm@kvack.org > > Cc: linux-hardening@vger.kernel.org > > --- > > include/linux/slab.h | 16 ++++++++-------- > > lib/fortify_kunit.c | 2 +- > > mm/slab.h | 6 ++++-- > > mm/slab_common.c | 4 ++-- > > mm/slub.c | 14 +++++++------- > > mm/util.c | 2 +- > > 6 files changed, 23 insertions(+), 21 deletions(-) > > > > diff --git a/include/linux/slab.h b/include/linux/slab.h > > index c8164d5db420..07373b680894 100644 > > --- a/include/linux/slab.h > > +++ b/include/linux/slab.h > > @@ -569,8 +569,8 @@ static __always_inline void kfree_bulk(size_t size, void **p) > > kmem_cache_free_bulk(NULL, size, p); > > } > > > > -void *__kmalloc_node_noprof(size_t size, gfp_t flags, int node) __assume_kmalloc_alignment > > - __alloc_size(1); > > +void *__kmalloc_node_noprof(kmem_buckets *b, size_t size, gfp_t flags, int node) > > + __assume_kmalloc_alignment __alloc_size(2); > > #define __kmalloc_node(...) alloc_hooks(__kmalloc_node_noprof(__VA_ARGS__)) > > > > void *kmem_cache_alloc_node_noprof(struct kmem_cache *s, gfp_t flags, > > @@ -679,7 +679,7 @@ static __always_inline __alloc_size(1) void *kmalloc_node_noprof(size_t size, gf > > kmalloc_caches[kmalloc_type(flags, _RET_IP_)][index], > > flags, node, size); > > } > > - return __kmalloc_node_noprof(size, flags, node); > > + return __kmalloc_node_noprof(NULL, size, flags, node); > > This is not ideal as now every kmalloc_node() callsite will now have to add > the NULL parameter even if this is not enabled. Could the new parameter be > only added depending on the respective config? I felt like it was much simpler to add an argument to the existing call path than to create a duplicate API that had 1 extra argument. However, if you want this behind a Kconfig option, I can redefine the argument list based on that? -- Kees Cook