From patchwork Fri Aug 9 07:33:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13758474 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 7362AC52D71 for ; Fri, 9 Aug 2024 07:33:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF1536B009E; Fri, 9 Aug 2024 03:33:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A51D46B009A; Fri, 9 Aug 2024 03:33:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A3416B00A2; Fri, 9 Aug 2024 03:33:13 -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 5B6246B009A for ; Fri, 9 Aug 2024 03:33:13 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 13D2E140A0C for ; Fri, 9 Aug 2024 07:33:13 +0000 (UTC) X-FDA: 82431891066.25.B9D27E7 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf28.hostedemail.com (Postfix) with ESMTP id 49131C0006 for ; Fri, 9 Aug 2024 07:33:11 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=G96xFR9z; spf=pass (imf28.hostedemail.com: domain of kees@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=kees@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723188739; 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=q6aByz+AjLMXLRqYk6daYpayybsUPOOvuxDJo0eVHWw=; b=j6psHLU+MRncOMDVAFCg1JK1tXz+80+Hvc+VPX6uo3iKwGn1qy50jwBNqQn0i0UAy+O4sj SWojMthCOzCGcOWgoeXc2U1gjJIni7R7yUzrGVMmRVIdEqoea/znbJY4LWNzWLuvgQkJQA 3YrBYSld1ZRoWcoF0IxeMcn7EbZKWKc= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=G96xFR9z; spf=pass (imf28.hostedemail.com: domain of kees@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=kees@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723188739; a=rsa-sha256; cv=none; b=OtTwhvNlgGnHY0ykwfCldEsAXdB70/POvKiqN5g0KLMfsN9ti1EHXG6UiNbuikHGGdbeMW 2gkdGLG6O+Uuv2gsEdhvegOv6HojGJF7IFRVVZFDkrM8Fi13x/ZaByGLcYA5NPkIGMcLzw atVbJxXN6C5EOiT5Q1BtqAOdAoH53K8= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 1518A6158B; Fri, 9 Aug 2024 07:33:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB099C4AF10; Fri, 9 Aug 2024 07:33:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723188789; bh=Stx3EEnB/9LWtVMs8bPtcAXmif1O8Z/znzWwrIr1yQM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G96xFR9zVeh09ObUFoqqZFktxg1j3FtzvLiXQZGmQZW/HVQIm7p5HIUbK5Ww99589 CNxj96mi3eBlCxegp72LfDbiC9rOvnrWCQzO0YvRFp6aR3VIj/SuoeDWAMXhIbxV8O cjeBU/r8ZOz+n88QSTZXJ9cFA1/i28S4PPfS/AKJ2uwN4tSkbb3JKof8G+eosTEybG 485xFvfsK3AuAe/sxtfTl47vL4CU3b2ybBPEAFXxACwNrNDgvU5G2oZNtuTk4AYoyV 9pYD8+LMbuhN6C9vBvYfaJZfhUZngVa/DpU5F+dlB9t9jc6WTqOaLW4mZPlzd8Hk+n ziag+GbKspAEQ== From: Kees Cook To: Vlastimil Babka Cc: Kees Cook , Suren Baghdasaryan , Kent Overstreet , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org, "GONG, Ruiqi" , Jann Horn , Matteo Rizzo , jvoisin , Xiu Jianfeng , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH 3/5] codetag: Introduce codetag_early_walk() Date: Fri, 9 Aug 2024 00:33:04 -0700 Message-Id: <20240809073309.2134488-3-kees@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240809072532.work.266-kees@kernel.org> References: <20240809072532.work.266-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2359; i=kees@kernel.org; h=from:subject; bh=Stx3EEnB/9LWtVMs8bPtcAXmif1O8Z/znzWwrIr1yQM=; b=owGbwMvMwCVmps19z/KJym7G02pJDGlbjxnOseXU/pJl/43T0XOt5r2jXsvfZqg+sjDOii3I3 vMo2r2zo5SFQYyLQVZMkSXIzj3OxeNte7j7XEWYOaxMIEMYuDgFYCKPwhgZPkd03P/cfODJhK1S TXHcc1wl7ylP8ufytdEOmixz1c7Yg+F/pc/9q0Ub7q7Zv+boUV0X+f1xT5Q6ndp1tt0+78NeFv6 LAwA= X-Developer-Key: i=kees@kernel.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Stat-Signature: sm1fni9q3gzch7ub5op7btj34wx1i9cx X-Rspam-User: X-Rspamd-Queue-Id: 49131C0006 X-Rspamd-Server: rspam02 X-HE-Tag: 1723188791-857760 X-HE-Meta: U2FsdGVkX19krTA8vLXdpio9wbw1ROw5r2f7LhAf2PJcAgmhrlLScR519UqxRPXDlTJQ8sNIpbPaCSltI+yCuyDhRdu8E05NX/Zr7SfRFLMogVICBIqv+OaMDvxhtVRPqQ8Cc2iv5YcPCMQengfOnUaYPYfTLFL+i7h9zh51fzoZUDIfFFeU3McgX+zu+xD42DryvJzpui/GlCskAW4WVa3/g+afh1BxudmjjzGVCZ19rQBvmbqN6JTXgpxBLfZgZiyc+gsdCE/2FwDHDna3vclx71FVSn80Fq5pRXMfu4b0J0ml5T3BmFo1OpuCGX0koihzf7o8qsm5R2rwcfnNzJyyiBcEhmdwuX3Y63tiCVkpzDDKCTDd3NCn9Xon8qz4ftz2D5UJFWcDhLF1zsfTmTNZ0/chvwpqSQ1a88QIRGC0BQ9sp17VHiTLh46lANg88PiF6Asq41rVLae33M2GzLJfKKIToV8n5L8iElA1aByx689vOFhGrKG/d9UaYoFq1YBOpoDwdmWg5cJJnNjG+GqfpeXsUHFfmBDjhgl+IjXBsocE1HPBbAtCEIwZM0sgYfCpdH2Nbdhfd0cAEbW2whRjVGj41jVBt7ZXZrRn7rQmHJgC8zPNL5aJsr1nXc7NEztx0v4gPhROowz0Es6ivH/b8/W5ackdz5pe5183XZOHK9Y5j+AU5srX/avGcvmGMOTk7foQ4VAv7wfwkLF733KBe8ZiISeYO1YBALUP/eCM5Nzbztk+Q6NO05lXt/oT/8hshvysnkdt7e6j9FxOskoKj1kV3uGUlHP0/A08bBRgFEDX2VL0kJTcUtmq177gYbNB5BKsfe+VHE3OtUeyWtqAnlr3jDbd+oTbOmgKqrkN9KiZKUr1q9eABaRk4QQxGSEeMzWA+OzyAnab7+B0AVaRt8BV0n8lXztGp9ip2iO/W2SagLT28tCMWV3Ty+wkEiT/WkmRY3SwSbyYZuO K7Z7T8iq GYsMkvCsnTNCkYO2HedRpXmb5PQWWUPOGSvW3epGyW42mMsJdqYRI8aydTOSTgXakrZz1svAp+Y8tCeiBT1mwk0qmB0H8Plx3oFYWbDuBEoLbGbriXL2uLf2v6NF37gYfjMJeGvMTcasuyZfXoFErtkOCgSwHq1S/D8vjhqNyb1p5d65YdTsasiF/aAVrF9P1Qt5C8fZPBl7Dk/IpXOWMCVbYoWosLcv82fHGGltFQPammc0ifDccWMPaejYjeAnX0zq8wOX/scKisIiskaWl3t9w5ZXZ+TXTUE5y8oSfTrNiyvTqz8hAQSilFVi2H5lE218ZpSzJdGP2NMSgWswr4GbWw/xCuO20ulxW+kFSUii/lCYJnZ+EsCd0MwLb4KVEkOLTJ7vZ9iYnk1Zly4T5NWmrZDT2RpFbqqNB/rmszS7f720OpBM6J/rNYrY82R0d8O1UIZe5MO30cIrVW90/sdNYpr8cQrLujRfwHeTt3jRJ1bPkSprhMQUMNRURBkUOe00FSK0z5a536qVzdQ3p0DWlJ/9bhVGz8Mv/O0svVk4ldVTa2JaSBf+mZjdSyG3nPcEQ2o2VYK8XJ6nsmFTBUrq20WMjLFEpWmlb3PP6byQ5n85ujq1eMLXkBwb7sKoypwBH 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: In order to process builtin alloc_tags much earlier during boot (before register_codetag() is processed), provide codetag_early_walk() that perform a lockless walk with a specified callback function. This will be used to allocate required caches that cannot be allocated on demand. Signed-off-by: Kees Cook --- Cc: Suren Baghdasaryan Cc: Kent Overstreet 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/codetag.h | 2 ++ lib/codetag.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/linux/codetag.h b/include/linux/codetag.h index c2a579ccd455..9eb1fcd90570 100644 --- a/include/linux/codetag.h +++ b/include/linux/codetag.h @@ -64,6 +64,8 @@ void codetag_lock_module_list(struct codetag_type *cttype, bool lock); bool codetag_trylock_module_list(struct codetag_type *cttype); struct codetag_iterator codetag_get_ct_iter(struct codetag_type *cttype); struct codetag *codetag_next_ct(struct codetag_iterator *iter); +void codetag_early_walk(const struct codetag_type_desc *desc, + void (*callback)(struct codetag *ct)); void codetag_to_text(struct seq_buf *out, struct codetag *ct); diff --git a/lib/codetag.c b/lib/codetag.c index ef7634c7ee18..9d563c8c088a 100644 --- a/lib/codetag.c +++ b/lib/codetag.c @@ -154,6 +154,22 @@ static struct codetag_range get_section_range(struct module *mod, }; } +void codetag_early_walk(const struct codetag_type_desc *desc, + void (*callback)(struct codetag *ct)) +{ + struct codetag_range range; + struct codetag *ct; + + range = get_section_range(NULL, desc->section); + if (!range.start || !range.stop || + range.start == range.stop || + range.start > range.stop) + return; + + for (ct = range.start; ct < range.stop; ct = ((void *)ct + desc->tag_size)) + callback(ct); +} + static int codetag_module_init(struct codetag_type *cttype, struct module *mod) { struct codetag_range range;