From patchwork Wed Apr 24 21:41:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13642528 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 D19BFC19F4F for ; Wed, 24 Apr 2024 21:41:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B5BEC6B0316; Wed, 24 Apr 2024 17:41:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B32276B0318; Wed, 24 Apr 2024 17:41:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 983DB6B0319; Wed, 24 Apr 2024 17:41:11 -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 7326A6B0316 for ; Wed, 24 Apr 2024 17:41:11 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1E6D4140D90 for ; Wed, 24 Apr 2024 21:41:11 +0000 (UTC) X-FDA: 82045746342.12.BA5C43B Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by imf14.hostedemail.com (Postfix) with ESMTP id 29226100002 for ; Wed, 24 Apr 2024 21:41:08 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=mdaTI1vT; spf=pass (imf14.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.177 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713994869; a=rsa-sha256; cv=none; b=rRIqO6k4uon3qzmiZ8btb/8EByU92GcWt+7am75wAwYnKcTPeKL1n4DAr4fWP+ulJhI4lA 2nzaum5OtHJZOTVPFSixgpqiEwTiMS9X40mqWYgUoSzAKDT39naQgUza31zje3Yezjn1Fg x1Wp556aGimPITpVp+HK8+3KS/Q10Wg= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=mdaTI1vT; spf=pass (imf14.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.177 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713994869; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=avaWrT0khuREU5h1MMjzzZvo4YgUdeePn0h1OukYT6Y=; b=5kitBQy+wj3nuCwnwgFsL4ZNV12CZVyKG+HTEovliXrP8yVXOJSlsDf0+scKyNM9qlV0Js GmUQt/TjOCSJR9j8g9ekafvqGIznNUkOqjGPlbp+PTf4IEA9RIQr9b25OJEW3DUXirJxJz rLhPb05RnwX+hIeYm20PfY1Rdt2UA88= Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-6ecee1f325bso394217b3a.2 for ; Wed, 24 Apr 2024 14:41:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1713994868; x=1714599668; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=avaWrT0khuREU5h1MMjzzZvo4YgUdeePn0h1OukYT6Y=; b=mdaTI1vTAce/Euwhh3T1GfY8nqMVY9pA2gjxEzI1xuhehFm0x9BWAThoHXbkry44gE 4aQ0d+uiHGr+wCe0Y8SmkaiD/XL+OQbPnBujWOhHGeQ/T1d+3YLqRPjnWAm1BheU6ZwY D5iu7XzTedKsStBxk560P24uzSBoU9U+33LqU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713994868; x=1714599668; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=avaWrT0khuREU5h1MMjzzZvo4YgUdeePn0h1OukYT6Y=; b=uijusWBsgfSgmoGsH93l51Z28gHN7ne5sCooaB60QGo8EL/ARmPezfFq1dpCKGBT5N Cy7Rm36YyNIWZs0+NcZJ8Cn4FajSe7iddBAg2kgIfmMQTiFnQ+wgrumqB+A3QXgdwH4C JREGCGO8ws7y7YlfmRqkSXWvJAANnoeRGt2PG+8MNkNHvzvZE/fRqUC25u+c0qKp30hW S6F5LsVd6Ja6l4TBfo6g6fVIaYeEMEajiNsybxOpBLUlb4Hzo4Opw7R+xy4ar4YxXvov HZ0PDiflIFg9C4rDKobpZUytk4KqDmywrWQq2+qDZ4kzoRZOjXKoM0p8wusQCIEPLrfm Tmfw== X-Forwarded-Encrypted: i=1; AJvYcCU4NPnJGpv2bTpdjWyfqXpwZhAqa+S2/2lPE21W/D8prp2ojJl51N+GW9cKlJ4tmap19YplAPmiB2dvPB3ljJOi3/s= X-Gm-Message-State: AOJu0YwOU8q9F3FGZmBgGoFFBg1fQItpSaxYnpcKwiPylYLzCHkX/6KQ c/yiIBszyHxtvjXmWX8ZEckRK8AhG6H0JmSy4hqCEqJd/5/5QNhWDEjpxvT2Ug== X-Google-Smtp-Source: AGHT+IHXJzscAQxkhpdn10b8o9bm2jTf9Syzbn/UYNQIO/7g7UQSGqLaU9uDrKL3kC60AEISiyGgRQ== X-Received: by 2002:a05:6a20:5616:b0:1a7:a353:939e with SMTP id ir22-20020a056a20561600b001a7a353939emr3679161pzc.56.1713994868043; Wed, 24 Apr 2024 14:41:08 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id x1-20020a63b201000000b005e838b99c96sm11611467pge.80.2024.04.24.14.41.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 14:41:05 -0700 (PDT) From: Kees Cook To: Vlastimil Babka 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, "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, linux-hardening@vger.kernel.org Subject: [PATCH v3 3/6] mm/slab: Introduce __kvmalloc_node() that can take kmem_buckets argument Date: Wed, 24 Apr 2024 14:41:00 -0700 Message-Id: <20240424214104.3248214-3-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240424213019.make.366-kees@kernel.org> References: <20240424213019.make.366-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4187; i=keescook@chromium.org; h=from:subject; bh=n44EIwrVbtUC/HODjVXTzsGeRWoVsJemo0On/8Qrf5o=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBmKXxuIQwklSExmXc87p72DCfh76AnwjYnK9Py8 7Fv1B+pgpeJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZil8bgAKCRCJcvTf3G3A JupMD/0VCva4CsvxyFhP/1VkRIHNT9neF+T4OIPegvk9amzhCJfRNJLUcIqZXAK9xEgkjQfbh2D vH/7wvvpfhoK+5xeXHZOkczwMl8+V2SiJieg5YMyTQs9ngeiUc00hjMfo/xIUlrurpZtf2QksCA Z5jRwHG/EgB7hCDS3nYtURFBj/AXsQTcrLiVJx+SqAmUIZ5yIDa/CocjagCWKN5gwxWe3CEpp56 PqhbCSxFQc5T/e5xN2S15FaupnNJX9s6PXe2Nx8Q/QUSQXDdwL/XvWV8F6kdM/xCOfYhMu0lrxj Wi29HbzMDnNAhqYpc8Ia7vtAX8v6zRiVS0S5i6HRIiRWHJnkNCwXLR92/Gsr/Ta8rt3yVjgjwC6 WY0VfE2J4xY9wz3TgKXuEYNzOqkTyCXyMGGUZe21ghzrocTHqP/8jxO5T7WvFt4PoBBEAcZ5fxO SXGz+iIscVt3qMrVkMfbkgVlY1xaLCz2N4du08JCuwtL9+vntjBOMH4YH9rTxx8D3MRkShjZ0y0 dBVtSr8odvEdUwdHX4H7FbvCEUJ5aIr3hfLxW9PKBb1H7sv3zw0jMEVpbxezXhcbUxqoiodcJDg YlL/45F9uG1CLOOK3MZLM1s1rOOVst3540xcKfxutWb2HIAhckktrVwaCmRKz8NAfuZVOEOIp8a wbiLrOqzM2i8B/g== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 29226100002 X-Stat-Signature: w9y7r9nmcykqw4zg84gp1fa5im1giopw X-Rspam-User: X-HE-Tag: 1713994868-114192 X-HE-Meta: U2FsdGVkX1/3yAFa2UHpIPwfEdp/LHvScGBzHCDIP6oKpMMuOENzB/bkqw6ShGWSbiMNYv4udQ0rH/++A3jgsw/PUR2qaGALAVCEXtztaBRQfp95OXI7qG2eA5qatbm+8x7kmIZgbUFzsM1FQGJW8x77k9YNd0CWj5lGgduGvRJghR2hxKzkNm0XxI5JcC6p2SW8O7l3qaanS5d72FqlrAkJCisXK9ww3970MTVeh/IMDBYBHxwiAVZmJ7Jq6AOBjG6GUfLa0zg+gqbfaWu0cghblyBpeJ9L1p0gauFtBv6Gn1H2XtgDvYp1mOgboGifNCiutt2dEDgIbwcSh7P5Dat5mchALzlQ7CmTuNO00ITXjqh4Q7cQ6npNlQi+VbMCyjtC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p12O4UITWsQ7MjJqZyv6RADNyKglb6kdPoc+Hx1fl98CCKNs5+0WKwwZP5Be0toZlbC+hERfuJVidmOC5vJObX0+DZ/HCuXRCBIy6wuhzOdG+osJCAuZ3SfC5nNEhRtxR8ikHLsMmA5C2kRnGtjEE2sY/8v/V8TLlte5i0MXacD9C4WfViF0yy5b8Vzh+8XO6sKNA4rRWKZKdy9BtJfyuwJAOD5IwM5f0/jT/S7CpUu3SanGEauaFSRByM7QQM7ToKTh9IXNGv1KGcad+/bxOdLdH7q9wkdUFUeaT3DDkpitCSDH1LyiNYevy8Xz6/PSejUdQH6FRYQYzHunsJkMqqEL7+77grAg/NHm5IE+B4Y3dmZhQUUarRDs8xVyOcoanUsHXIPbJ1j62I= 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: Plumb kmem_buckets arguments through kvmalloc_node_noprof() so it is possible to provide an API to perform kvmalloc-style allocations with a particular set of buckets. Introduce __kvmalloc_node() that takes a kmem_buckets argument. 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 --- include/linux/slab.h | 10 ++++++---- lib/rhashtable.c | 2 +- mm/util.c | 5 +++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index 07373b680894..23b13be0ac95 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -781,11 +781,13 @@ static inline __alloc_size(1) void *kzalloc_noprof(size_t size, gfp_t flags) #define kzalloc(...) alloc_hooks(kzalloc_noprof(__VA_ARGS__)) #define kzalloc_node(_size, _flags, _node) kmalloc_node(_size, (_flags)|__GFP_ZERO, _node) -extern void *kvmalloc_node_noprof(size_t size, gfp_t flags, int node) __alloc_size(1); -#define kvmalloc_node(...) alloc_hooks(kvmalloc_node_noprof(__VA_ARGS__)) +extern void *kvmalloc_node_noprof(kmem_buckets *b, size_t size, gfp_t flags, int node) + __alloc_size(2); +#define __kvmalloc_node(...) alloc_hooks(kvmalloc_node_noprof(__VA_ARGS__)) +#define kvmalloc_node(...) __kvmalloc_node(NULL, __VA_ARGS__) #define kvmalloc(_size, _flags) kvmalloc_node(_size, _flags, NUMA_NO_NODE) -#define kvmalloc_noprof(_size, _flags) kvmalloc_node_noprof(_size, _flags, NUMA_NO_NODE) +#define kvmalloc_noprof(_size, _flags) kvmalloc_node_noprof(NULL, _size, _flags, NUMA_NO_NODE) #define kvzalloc(_size, _flags) kvmalloc(_size, _flags|__GFP_ZERO) #define kvzalloc_node(_size, _flags, _node) kvmalloc_node(_size, _flags|__GFP_ZERO, _node) @@ -797,7 +799,7 @@ static inline __alloc_size(1, 2) void *kvmalloc_array_noprof(size_t n, size_t si if (unlikely(check_mul_overflow(n, size, &bytes))) return NULL; - return kvmalloc_node_noprof(bytes, flags, NUMA_NO_NODE); + return kvmalloc_node_noprof(NULL, bytes, flags, NUMA_NO_NODE); } #define kvmalloc_array(...) alloc_hooks(kvmalloc_array_noprof(__VA_ARGS__)) diff --git a/lib/rhashtable.c b/lib/rhashtable.c index dbbed19f8fff..ef0f496e4aed 100644 --- a/lib/rhashtable.c +++ b/lib/rhashtable.c @@ -184,7 +184,7 @@ static struct bucket_table *bucket_table_alloc(struct rhashtable *ht, static struct lock_class_key __key; tbl = alloc_hooks_tag(ht->alloc_tag, - kvmalloc_node_noprof(struct_size(tbl, buckets, nbuckets), + kvmalloc_node_noprof(NULL, struct_size(tbl, buckets, nbuckets), gfp|__GFP_ZERO, NUMA_NO_NODE)); size = nbuckets; diff --git a/mm/util.c b/mm/util.c index 80430e5ba981..bdec4954680a 100644 --- a/mm/util.c +++ b/mm/util.c @@ -596,6 +596,7 @@ EXPORT_SYMBOL(vm_mmap); /** * kvmalloc_node - attempt to allocate physically contiguous memory, but upon * failure, fall back to non-contiguous (vmalloc) allocation. + * @b: which set of kmalloc buckets to allocate from. * @size: size of the request. * @flags: gfp mask for the allocation - must be compatible (superset) with GFP_KERNEL. * @node: numa node to allocate from @@ -609,7 +610,7 @@ EXPORT_SYMBOL(vm_mmap); * * Return: pointer to the allocated memory of %NULL in case of failure */ -void *kvmalloc_node_noprof(size_t size, gfp_t flags, int node) +void *kvmalloc_node_noprof(kmem_buckets *b, size_t size, gfp_t flags, int node) { gfp_t kmalloc_flags = flags; void *ret; @@ -631,7 +632,7 @@ void *kvmalloc_node_noprof(size_t size, gfp_t flags, int node) kmalloc_flags &= ~__GFP_NOFAIL; } - ret = kmalloc_node_noprof(size, kmalloc_flags, node); + ret = __kmalloc_node_noprof(b, size, kmalloc_flags, node); /* * It doesn't really make sense to fallback to vmalloc for sub page