From patchwork Thu Feb 20 05:20:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13983318 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 50346C021B1 for ; Thu, 20 Feb 2025 05:20:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C8A8028028C; Thu, 20 Feb 2025 00:20:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C01E0280298; Thu, 20 Feb 2025 00:20:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9968A280296; Thu, 20 Feb 2025 00:20:43 -0500 (EST) 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 654C9280294 for ; Thu, 20 Feb 2025 00:20:43 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E9499B2A1D for ; Thu, 20 Feb 2025 05:20:42 +0000 (UTC) X-FDA: 83139173124.20.1636B58 Received: from invmail4.hynix.com (exvmail4.hynix.com [166.125.252.92]) by imf19.hostedemail.com (Postfix) with ESMTP id 0412F1A0002 for ; Thu, 20 Feb 2025 05:20:40 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf19.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=1740028841; a=rsa-sha256; cv=none; b=7Xv4nr8N9FU4HFRqPPXoM0lHTESsHFGgdiL+kJENhNin+ILErQn9d15nSRbw9YxREW6VKU JyD2K6swsDVVh6wEoA3juucuhJeYyp9K10m1NUGxdWoKAUlCS5TLBvF3trj/fwcJH39HaC reNQ3jqRjg7q1CDsR03VDQT/+w3F31I= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf19.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=1740028841; 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=SQ8BX0dsCDiLsyNxdvwUISZIRBOA2Cim0w/LniXoUnQ=; b=bfgXlkDDsKiS4WHeO0OR6Q5ce/9UknlvswyIJ0BH7vOIvP26b/k7HZrQCl412PdvznM9g3 fx20b4iEvCBeqfNLx0Kf1AmVfFt6D8hqKKnwcp3zTLaK+t41OCFaFrpeZMsy8eJryn0DwN xOn2C6yqqn9Wa3tJiCL38tu3CMOF1bU= X-AuditID: a67dfc5b-3c9ff7000001d7ae-cb-67b6bba62acc From: Byungchul Park To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: kernel_team@skhynix.com, akpm@linux-foundation.org, ying.huang@intel.com, 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, dave.hansen@linux.intel.com, rjgolo@gmail.com Subject: [RFC PATCH v12 06/26] mm: move should_skip_kasan_poison() to mm/internal.h Date: Thu, 20 Feb 2025 14:20:07 +0900 Message-Id: <20250220052027.58847-7-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20250220052027.58847-1-byungchul@sk.com> References: <20250220052027.58847-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgF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M3i8e8k4Ee7/ddZfNY/OIDk8fWX3YejVOvsXl83iQXwB/FZZOS mpNZllqkb5fAldH88CRLwUKdimPPn7E2MM5R6WLk4JAQMJH42JTaxcjJwSagLnHjxk9mEFtE wEziYOsfdhCbWeAuk8SBfjYQW1ggWOLcnlNgNSwCqhKTVpwBi/MKmErMmDAbLC4hIC+xesMB MJsTaM6PGb1gNUJANe8WXGKawMi1gJFhFaNIZl5ZbmJmjqlecXZGZV5mhV5yfu4mRmAYL6v9 M3EH45fL7ocYBTgYlXh4Hzzemi7EmlhWXJl7iFGCg1lJhLetfku6EG9KYmVValF+fFFpTmrx IUZpDhYlcV6v8NQEIYH0xJLU7NTUgtQimCwTB6dUA2NZ+A6jo08ilpoIanJ3xVt93d+3XEl3 zpXJ7tbWf2ZkxWY/iF0kXjozZM65IzuvNS9VZ//nJyT67aTWkxK7eNs5HFv6WNXdT9i4z4/v naIjFTAr71dDw8KfSdsYJ9x1avacrMCQHPPF68r35qjGrKf3j0VXHPc+261ikRxvOne+/eoJ MR5HpZRYijMSDbWYi4oTAa2FdxpfAgAA X-CFilter-Loop: Reflected X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 0412F1A0002 X-Stat-Signature: etc8nqfmhkicwyy9n7b8wph3qjpcsfw6 X-Rspam-User: X-HE-Tag: 1740028840-208793 X-HE-Meta: U2FsdGVkX1+ra0sYdWfn3713IS0TKHHHYbk7b6jOyWEuqKOIYZWG5gr5UIm0SVTYO5+8ZIiXFQqpEhH91eCfS0nnLdFH49zJbZiqy61dx7pEmTIZZU/oQsxLQnovkwqo6uyoDkjXoaTeog6nPfyXAP6CLBc079DZ0M4/byVeMD8tkbylZOmqwCV8SqvgQIZJwx25+c7z0zWduGIo+c91m9DnytKx+rH9d+FbCh/FnrsORXNAm0zOfXX6FJUR3pjQzQdPgHGHi+YnjNp3xTZzUZ2OPPgFJL9gJQc2ckwJZ7zO91doQXpN8s3jrN8A8X3U0GEaYfCGX49CVMxHMdGtmkOkd0qQPY+1hG6DU99fDHdCQyQQArKv3p3yMX2/CPSKGWpE3eb4C65R4Go9f2QQaqK8oJ502BWBqFCWRt3B9G2KrPj3yi5S4B0lZ+bQJGI1wtuFksOhYkNIe+kyB1MgBtywfHw17Vh5AzxYucg53CxzwwbWnRtz+etNYZ6J7q1HKzwbs8XvPkHAcFP7ggLSaRJYxwGgfa4hrVNdL35PeXvwwzDq+aWR/YKxVArXb+cRkA6igDIFpFzf4QZSS/xUSFG+EJtQXu5WN2NSEpwo6YY2dw4xFhr3VtnaKaOIokv6QazA1AWuXrIrCOioaiyhOt/VBT57KC7nAmpFWHQZeoUyGmj73YjuEPYJoOpnl2Bld55EndiEnDfxqJOwSb/LTjeUQ2YFv3SMcl79UiTTTwuEiMpvjYSBxUoeUIdNqhAQ1rrazlNTxYuDnEBWCYXbRD7WVu1DMSVrfWwggKa+G1eeGkSWCcbbFOyEnRvRXpZuHDlm8QUnt9ZUGHpMhcnmI7HsFe+xkzYLMp357RpwYB4sjd8Sl8Nyr6EuqP/pLU+LGDs8rtA+tYLxZZRM+p6y7X4H6oReTGNE3l96/PTGNnoKIHDKBHPOLW6c6oZl3AT2hQined+g/64SAr+/1Xv +xjdF5IT gmFgr35kqi8UIHGEjzaJsqFHXPpvYhl2UFXWH 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 754f1dd763448..e3084d32272e3 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1038,8 +1038,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 59c26f59db3d6..244cb30496be5 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;