From patchwork Wed Feb 26 12:01:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13992171 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 5D3C6C18E7C for ; Wed, 26 Feb 2025 12:01:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B1E0528001E; Wed, 26 Feb 2025 07:01:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AA7A8280015; Wed, 26 Feb 2025 07:01:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8D2E928001D; Wed, 26 Feb 2025 07:01:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5ACB628001B for ; Wed, 26 Feb 2025 07:01:49 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8A41412120E for ; Wed, 26 Feb 2025 12:01:47 +0000 (UTC) X-FDA: 83161956654.18.FB2199B Received: from invmail4.hynix.com (exvmail4.skhynix.com [166.125.252.92]) by imf16.hostedemail.com (Postfix) with ESMTP id 517C718002D for ; Wed, 26 Feb 2025 12:01:44 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf16.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740571305; a=rsa-sha256; cv=none; b=ZbDFJ2OkBEpeF3eqDF64e0yfWB7AIZqPjmQWX/UlNcOQcfLP7KotBYwHPpNnAdeFbr/QN5 jJkO5iK8VcPuLWGkqpwTwHQtWHnhNaFa8f3NE7UhW74+dZixuwiboFAi8E7GCrnIzpeE9S RfMKyloZX5GBUqaAQ0PT/N4s9KjLCJE= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf16.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1740571305; 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=yk0RnK9t/QXfZVXi7eXdhWunlcx4pbexLIgBlJEBzY4=; b=0gSUYEe5RSJhtNHQeFvX+zgVv5d+JqxGxkTAafbXf/OYsGKSzD8mzgIcQaeINpu7/TPss7 hFBQ+32C92Mpd0t9yljfKaBO3sZh6QxCqyMVqAtZzXTwP0zryhOX9AngzkRVOFTeLrDhzM IqN4dW8oGdRp/7+c6PXip604FBK1viw= X-AuditID: a67dfc5b-3e1ff7000001d7ae-e0-67bf02a6185d 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 mm-unstable as of Feb 21, 2025 06/25] mm: move should_skip_kasan_poison() to mm/internal.h Date: Wed, 26 Feb 2025 21:01:13 +0900 Message-Id: <20250226120132.28469-6-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20250226120132.28469-1-byungchul@sk.com> References: <20250226113342.GB1935@system.software.com> <20250226120132.28469-1-byungchul@sk.com> X-Brightmail-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4 MeM3i8f7fVfZPBa/+MDksfWXnUfj1GtsHp83yQXwRnHZpKTmZJalFunbJXBlLGj/yliwUKdi Y/NX1gbGOSpdjJwcEgImEi8eLmUBsdkE1CVu3PjJDGKLCJhJHGz9w97FyMXBLLCMSWLviQY2 kISwQLXEvyO7WLsYOThYBFQlpjaYg4R5BUwlXj5dyAYxU15i9YYDYHM4geb82/2bHcQWEkiW aFn/m2UCI9cCRoZVjCKZeWW5iZk5pnrF2RmVeZkVesn5uZsYgSG6rPbPxB2MXy67H2IU4GBU 4uF9cGZvuhBrYllxZe4hRgkOZiURXs7MPelCvCmJlVWpRfnxRaU5qcWHGKU5WJTEeb3CUxOE BNITS1KzU1MLUotgskwcnFINjBp/XQ1z4qQ5OyU5xLrC/3555chz5hcj9zuO8NYK42svFm2R s3ZjWCqfW/VgXumXPGePezvFLVc8qv54wavLqP+D8lkl3v06jlvu+tv8W5QV9eOpvFqX+gRb q++/Z0fNK3vBo7T4/8IbuSzW36MXWex74K4VFTY/X8tDfnPsvaYlbgtjjnueUGIpzkg01GIu Kk4EAGS9OkJNAgAA X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 517C718002D X-Stat-Signature: 53ax641io7k7qo7k4xbob9gamkn9xqbt X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1740571304-663943 X-HE-Meta: U2FsdGVkX1/dOJTLngDoljsSK4/DhEi8H4AN/pge4GTv5wSiD3y4Zrg+3l6dGm11TYoTy9AEmkf1zi8RWbsraUbee/Q56k1iDcCwyZmFCprdTw++DMvTs3flC56xpmscQq4MJx9e1F3gTi6UlFI42g2vTsQHE/uo7aTLuDjXcLIJjqBo+eP7Zq07sodMotMALkvPqAapAXPN2KiydU4EQEfhJyB/oXjPEdk+OEIJ9oN1owqzdL7S8XW4zwHizeD7UecnBNG+xdRpZGGX2XRaZWujbJcIfdKiOXHIcksSYQx0UpqrD3nqd30nZqpdlgEmpVLpDtYlUnXNHf8AhtqmAlZ3l/+iW2ZuQYwSlTZ2de9HMC+ZkwY2o2O1Q+RIjquO1kW/sQJiHulPb1GMIRiDn06SUJpRhlXMzaBAFqjbWwcAeSiq8B+sBgXW91LPjBEu/Y2mVbdfKVjQclHZUZN6ltboDfBGh0QX7aAW9pcgf9KOpQXyerTso9mkFzmL9BK0lqRIkuR/DDH9MCVRNcHXVaAm7MX7nc/lFwrIdaMlxMTG8TOxNXLgq+wcaJfQYc6cfMefMh1WPuAHbwEZsJukzCgX53ipHykbg/tPIEF4b7maCre01Vr/fw6VcpV5WYl7718hxnnop90GY2FrxcuZQS+vRHzScJ2Di5FVTXc7LsGeUpPmJEGKHoLHAj2YDpAWwHpqXWH6z4H5FTJaC7Zqv/y1rwQpewjpUFUGAp1Xno6TglMSozIHULdwP/1KVAK2vN/eWeRXGlIvHszQq1aYud6vK6o5uk6fd5LvHSWiRd/GJcx7omZHZd191rXCHr0dsbBm536WFcqgbAiPB7H8LpcRR5CqIknlYsn023DgS72DkYGHFht1if4B4l21UzxTSA/qKxtI8xtg3AdN4EhhEemVRJgl54sRR/bNdQDHp9nEB0LqhHB5j7s93TdquoTAnROiyMwz3lj5jscDhnt 1HTFCYlE YpMb3t51wPjKHODaf8nImr+Fwk/4B3qO/AdEo 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 c4d2018a7cf8e..ee8af97c39f59 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1067,8 +1067,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 86c9fa45d36fe..f3930a2a05cd3 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;