From patchwork Wed Feb 26 12:03:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13992198 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 56DB0C021B8 for ; Wed, 26 Feb 2025 12:03:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 44402280020; Wed, 26 Feb 2025 07:03:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C94F280024; Wed, 26 Feb 2025 07:03:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F6BF280020; Wed, 26 Feb 2025 07:03:51 -0500 (EST) 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 E808E280024 for ; Wed, 26 Feb 2025 07:03:50 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A0930C1386 for ; Wed, 26 Feb 2025 12:03:50 +0000 (UTC) X-FDA: 83161961820.15.FB68D23 Received: from invmail4.hynix.com (exvmail4.skhynix.com [166.125.252.92]) by imf12.hostedemail.com (Postfix) with ESMTP id 9F78B40008 for ; Wed, 26 Feb 2025 12:03:48 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; spf=pass (imf12.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1740571429; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=SKiITRHUl5INiO6pLcOQNCWmURoPfnq7z5oAqR6eRcY=; b=EnoO42u2g7XSZcZrP+Vox1D9X+qndbHXfNk6BblSFpEQF07o2PcOrBIup6L37hwn8PovAD gzfEqy1yM3ZaVRYW/lr3E3zyZ1KaUdef2gozZLCFYdMZZq9rRHQbHdOhvWJDdnxCI/WXd2 flNeuFTFXhTmZYBaF4CAVGIiX3H5EB8= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; spf=pass (imf12.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740571429; a=rsa-sha256; cv=none; b=7g+U5pCyA4PrDCdQS9cbZ6B2PFxlS8aBLMLSAj2eopkDj4+3uKzrumSja0uma0qeYbVKzT 0UzGWINRIiwH6oCyX1Jo1yxAoI/6yTuTGLLDRq34Zneut8/Hlg2F7D2zPE6f0hvtiDp/dY CBcup3i3FYlAslUaU7wxmbEntrb1Kqs= X-AuditID: a67dfc5b-3e1ff7000001d7ae-0f-67bf0322004f From: Byungchul Park To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: kernel_team@skhynix.com, akpm@linux-foundation.org, vernhao@tencent.com, mgorman@techsingularity.net, hughd@google.com, willy@infradead.org, david@redhat.com, peterz@infradead.org, luto@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, rjgolo@gmail.com Subject: [RFC PATCH v12 based on v6.14-rc4 06/25] mm: move should_skip_kasan_poison() to mm/internal.h Date: Wed, 26 Feb 2025 21:03:17 +0900 Message-Id: <20250226120336.29565-6-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20250226120336.29565-1-byungchul@sk.com> References: <20250226113024.GA1935@system.software.com> <20250226120336.29565-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAA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2j8+b5AJ4o7hsUlJzMstSi/TtErgy9r8/y16wUKfi fv9v5gbGOSpdjJwcEgImEicev2UHsdkE1CVu3PjJDGKLCJhJHGz9AxTn4mAWWMYksfdEA1sX IweHsECaxNpbkiA1LAKqEpuaJoH18gqYSvzZtZAVYqa8xOoNB8DmcALN+TTtGBuILSSQLLHz 9x+mCYxcCxgZVjGKZOaV5SZm5pjqFWdnVOZlVugl5+duYgSG6LLaPxN3MH657H6IUYCDUYmH 98GZvelCrIllxZW5hxglOJiVRHg5M/ekC/GmJFZWpRblxxeV5qQWH2KU5mBREuf1Ck9NEBJI TyxJzU5NLUgtgskycXBKNTDW8i4PXHj84t83p7/4CQvNFcgS4Jk5eXcD5+EYi0W7PjP3Ftfn XYzvj3m0rOuv56zZV8KnO878vfLkBkmRMh/ntiDHEs7S3z+8nZ4rihdM+7RJP8pin8vUoiil xwZWi3M4terlPS+zPX9jGHz9orGa3aHjXgzMp7Zs2D7hX0Ha8p9uMTVaNRJKLMUZiYZazEXF iQCrjtWPTQIAAA== X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Queue-Id: 9F78B40008 X-Stat-Signature: 3dzkqctkiydpor7d4tqpr9j68e9tpz8b X-Rspamd-Server: rspam03 X-HE-Tag: 1740571428-606759 X-HE-Meta: U2FsdGVkX1+hRMC1b43oLRz3jzcWz8lLjbR0+ub+CtJRDeQWd2zt2so/BiWFQ+adFhm4s41z4jBPTIkYPWucFhUwBjxG5IecKduXWgVvHe9dnl+tEob7CKzkqrNr1qDu/o19/Z4HZ5AktnEed3It88TPk6RWrWem1IJVIcB3YJgpz8T6Xu5llJ/1lrn8GFxmwYzz8RHsQC4wOj9iJo/DTZ8NibBqCnSevBabFNiqn8Z5qDFZz4bOlmePK6d+R4z/iSpPMycuKk9TWUBkhHU4PAph+saEcdbPg14GWJwBwQjxjlSGPahufaQvWVFg4zDvVKs/RQMmw1MNX9HH2PRCYrw/iZmJoN6FbDhozgcrKn3KMH2kokze+Uoot4Gb7Qzpz3I15QqBKBLtaqgOm62mVO4Wk1MK6CaWpz72wjNqrtl8TWXxadQ88yFmUFAIAeSdlK26S07N19Pr+Ci3Aunc448aiF3zx8vQdT0fxfQqlXfKPzKFhnhbpthtFTuNx7kuORGjjwitFqBCCmtjCcBJqPHOSDTLC9yX3vIEALRxdICW5pQZ8+7O0fdOe3sFiXIgW4spOhPBS1UzuTMb7VNS8HnpkgnD1KcXwWbPw36Y9G0XKSznofpZUflmOGAYb1jXRDy9djDyQCQrHgu8ucw/0kt0UecO9mNWwmdC6Vc/ir6fHTh1X8ZFYXsgMl6Yx193YzxcXwm3VQaGOKQ2TbyQGt+d61aA6EHAnUNHTJivdNBB6tiPSoFlEHQlnzGayuTaWAdkSu/eGc5IidaiF7ESc85qboanYQPBe6TwfavMhKTzeDFk4+zsMoz+Lk3Yng0Uj4T7VQJy9gW0Jx0rKi0O53dFTOJZJXCIhadFUArRzXL9jjvcNRbIsCRxyKqjUYqxxYw65KSJ56D7xcNGiAgAFdKQ3uwitxpJRqaq+heFfQP/LOQZleuF7w9sDGiL6zCBFaQy+HooUHhLyvxaj/m kRs+OReU smRwcgUfwYFPanEEdvTJPiiv5BT2OHhw24AW/ 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: Functionally, no change. This is a preparation for luf mechanism that needs to use should_skip_kasan_poison() function in mm/internal.h. Signed-off-by: Byungchul Park --- mm/internal.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ mm/page_alloc.c | 47 ----------------------------------------------- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index d7161a6e0b352..4c8ed93a792ec 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1051,8 +1051,55 @@ static inline void vunmap_range_noflush(unsigned long start, unsigned long end) DECLARE_STATIC_KEY_TRUE(deferred_pages); bool __init deferred_grow_zone(struct zone *zone, unsigned int order); + +static inline bool deferred_pages_enabled(void) +{ + return static_branch_unlikely(&deferred_pages); +} +#else +static inline bool deferred_pages_enabled(void) +{ + return false; +} #endif /* CONFIG_DEFERRED_STRUCT_PAGE_INIT */ +/* + * Skip KASAN memory poisoning when either: + * + * 1. For generic KASAN: deferred memory initialization has not yet completed. + * Tag-based KASAN modes skip pages freed via deferred memory initialization + * using page tags instead (see below). + * 2. For tag-based KASAN modes: the page has a match-all KASAN tag, indicating + * that error detection is disabled for accesses via the page address. + * + * Pages will have match-all tags in the following circumstances: + * + * 1. Pages are being initialized for the first time, including during deferred + * memory init; see the call to page_kasan_tag_reset in __init_single_page. + * 2. The allocation was not unpoisoned due to __GFP_SKIP_KASAN, with the + * exception of pages unpoisoned by kasan_unpoison_vmalloc. + * 3. The allocation was excluded from being checked due to sampling, + * see the call to kasan_unpoison_pages. + * + * Poisoning pages during deferred memory init will greatly lengthen the + * process and cause problem in large memory systems as the deferred pages + * initialization is done with interrupt disabled. + * + * Assuming that there will be no reference to those newly initialized + * pages before they are ever allocated, this should have no effect on + * KASAN memory tracking as the poison will be properly inserted at page + * allocation time. The only corner case is when pages are allocated by + * on-demand allocation and then freed again before the deferred pages + * initialization is done, but this is not likely to happen. + */ +static inline bool should_skip_kasan_poison(struct page *page) +{ + if (IS_ENABLED(CONFIG_KASAN_GENERIC)) + return deferred_pages_enabled(); + + return page_kasan_tag(page) == KASAN_TAG_KERNEL; +} + enum mminit_level { MMINIT_WARNING, MMINIT_VERIFY, diff --git a/mm/page_alloc.c b/mm/page_alloc.c index c08b1389d5671..27aeee0cfcf8f 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -299,11 +299,6 @@ int page_group_by_mobility_disabled __read_mostly; */ DEFINE_STATIC_KEY_TRUE(deferred_pages); -static inline bool deferred_pages_enabled(void) -{ - return static_branch_unlikely(&deferred_pages); -} - /* * deferred_grow_zone() is __init, but it is called from * get_page_from_freelist() during early boot until deferred_pages permanently @@ -316,11 +311,6 @@ _deferred_grow_zone(struct zone *zone, unsigned int order) return deferred_grow_zone(zone, order); } #else -static inline bool deferred_pages_enabled(void) -{ - return false; -} - static inline bool _deferred_grow_zone(struct zone *zone, unsigned int order) { return false; @@ -993,43 +983,6 @@ static int free_tail_page_prepare(struct page *head_page, struct page *page) return ret; } -/* - * Skip KASAN memory poisoning when either: - * - * 1. For generic KASAN: deferred memory initialization has not yet completed. - * Tag-based KASAN modes skip pages freed via deferred memory initialization - * using page tags instead (see below). - * 2. For tag-based KASAN modes: the page has a match-all KASAN tag, indicating - * that error detection is disabled for accesses via the page address. - * - * Pages will have match-all tags in the following circumstances: - * - * 1. Pages are being initialized for the first time, including during deferred - * memory init; see the call to page_kasan_tag_reset in __init_single_page. - * 2. The allocation was not unpoisoned due to __GFP_SKIP_KASAN, with the - * exception of pages unpoisoned by kasan_unpoison_vmalloc. - * 3. The allocation was excluded from being checked due to sampling, - * see the call to kasan_unpoison_pages. - * - * Poisoning pages during deferred memory init will greatly lengthen the - * process and cause problem in large memory systems as the deferred pages - * initialization is done with interrupt disabled. - * - * Assuming that there will be no reference to those newly initialized - * pages before they are ever allocated, this should have no effect on - * KASAN memory tracking as the poison will be properly inserted at page - * allocation time. The only corner case is when pages are allocated by - * on-demand allocation and then freed again before the deferred pages - * initialization is done, but this is not likely to happen. - */ -static inline bool should_skip_kasan_poison(struct page *page) -{ - if (IS_ENABLED(CONFIG_KASAN_GENERIC)) - return deferred_pages_enabled(); - - return page_kasan_tag(page) == KASAN_TAG_KERNEL; -} - static void kernel_init_pages(struct page *page, int numpages) { int i;