Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3541905pxb; Mon, 24 Jan 2022 11:48:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJzUa05JCjWsIXuqgtuQem69xDc93AOWfKTOhUVM1/5L60H/RpEIUVuGwkaxYvNw3z1wVMKM X-Received: by 2002:a17:90b:4d0d:: with SMTP id mw13mr3429439pjb.233.1643053728477; Mon, 24 Jan 2022 11:48:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643053728; cv=none; d=google.com; s=arc-20160816; b=kTnSiasMEQ64WJAOSgXuXmA9HcnitL/Fp//e+pw3E6K1T2zVHrjQNGYjdiqJkc5hle lC0Q9JUxZmu0IP1+EU+0FfxvghWVwTo8G6H5X+IB2Snyue+cYfsZaqtWTHEnQqVr8RUS UseVB3J5EDJXI2J40JrYUAYvOz3+g7WM/cbVzt8mJUkFWtiUuSaMIbGgKjYH+D3RE9v4 a7AUqB4kZnbBRXcxuJydD801wJI5Nw4NupHs/UUBV1gQ/sMxaLonHvE4GaOeOfFjWKPl nguVux/18ZJXtz4Sf8TJ5T9m/auTSqNwAS6nZU8GGGXJQzRvQZOA1zooHj661kvEN5+x kPEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JeuhmVhr16WrUz1cholyqQm1OzZJjys1/2dFsfvc630=; b=XNGH/qt27UkT4mLzrdIQumg+MYzxDqBzS2H5Taro5v46SQY8eTGFepQ35Tp1WTPaPI lnf3uL7hS1DhdSiKKRrT/CcIQkeAOYXLyHyktqTFJwKJpNlQpi/U74rVhQg+3PKidB4W g42qB+2RbleVd0Evc0MMxjH+6PKSpwek6/+arpJBEcdhjSzdi+gSr7Jae1bVQcUljO/3 O12CmpR1rMRNCH0DQi1FAuT+4dyXWamFJfbPVYllFDNc9vGZa1+87gVCesAQTmcllHI1 hodg4bZUmOAua2ChQGrcApAVBLJVS2PcRgxPHW3zP6vrZTBB/HOly0SB0ZWe5b6KoNPc dY6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=FSawIJBA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x24si12353234pln.422.2022.01.24.11.48.36; Mon, 24 Jan 2022 11:48:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=FSawIJBA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244894AbiAXSDE (ORCPT + 99 others); Mon, 24 Jan 2022 13:03:04 -0500 Received: from out0.migadu.com ([94.23.1.103]:17249 "EHLO out0.migadu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235838AbiAXSC5 (ORCPT ); Mon, 24 Jan 2022 13:02:57 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1643047375; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JeuhmVhr16WrUz1cholyqQm1OzZJjys1/2dFsfvc630=; b=FSawIJBAX9mPKyirB/SmRF301q2vgYEmIU9PRcAFsUNOfOAt8DTBTxOwekxP5ivwkDzxNZ a+QpKMorNIOSEPGpl6nGp7DN1AR8cpYzisQsr9eM6hDBBige/cTmLVw7tY0zovAFTUVVWG N7SuL19o79Cr9aIxzd8dShvprTEnPVM= From: andrey.konovalov@linux.dev To: Andrew Morton Cc: Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, linux-mm@kvack.org, Vincenzo Frascino , Catalin Marinas , Will Deacon , Mark Rutland , linux-arm-kernel@lists.infradead.org, Peter Collingbourne , Evgenii Stepanov , linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v6 03/39] kasan, page_alloc: merge kasan_free_pages into free_pages_prepare Date: Mon, 24 Jan 2022 19:02:11 +0100 Message-Id: <303498d15840bb71905852955c6e2390ecc87139.1643047180.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrey Konovalov Currently, the code responsible for initializing and poisoning memory in free_pages_prepare() is scattered across two locations: kasan_free_pages() for HW_TAGS KASAN and free_pages_prepare() itself. This is confusing. This and a few following patches combine the code from these two locations. Along the way, these patches also simplify the performed checks to make them easier to follow. Replaces the only caller of kasan_free_pages() with its implementation. As kasan_has_integrated_init() is only true when CONFIG_KASAN_HW_TAGS is enabled, moving the code does no functional changes. This patch is not useful by itself but makes the simplifications in the following patches easier to follow. Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko --- Changes v2->v3: - Update patch description. --- include/linux/kasan.h | 8 -------- mm/kasan/common.c | 2 +- mm/kasan/hw_tags.c | 11 ----------- mm/page_alloc.c | 6 ++++-- 4 files changed, 5 insertions(+), 22 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 4a45562d8893..a8bfe9f157c9 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -96,7 +96,6 @@ static inline bool kasan_hw_tags_enabled(void) } void kasan_alloc_pages(struct page *page, unsigned int order, gfp_t flags); -void kasan_free_pages(struct page *page, unsigned int order); #else /* CONFIG_KASAN_HW_TAGS */ @@ -117,13 +116,6 @@ static __always_inline void kasan_alloc_pages(struct page *page, BUILD_BUG(); } -static __always_inline void kasan_free_pages(struct page *page, - unsigned int order) -{ - /* Only available for integrated init. */ - BUILD_BUG(); -} - #endif /* CONFIG_KASAN_HW_TAGS */ static inline bool kasan_has_integrated_init(void) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 92196562687b..a0082fad48b1 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -387,7 +387,7 @@ static inline bool ____kasan_kfree_large(void *ptr, unsigned long ip) } /* - * The object will be poisoned by kasan_free_pages() or + * The object will be poisoned by kasan_poison_pages() or * kasan_slab_free_mempool(). */ diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index 7355cb534e4f..0b8225add2e4 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -213,17 +213,6 @@ void kasan_alloc_pages(struct page *page, unsigned int order, gfp_t flags) } } -void kasan_free_pages(struct page *page, unsigned int order) -{ - /* - * This condition should match the one in free_pages_prepare() in - * page_alloc.c. - */ - bool init = want_init_on_free(); - - kasan_poison_pages(page, order, init); -} - #if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST) void kasan_enable_tagging_sync(void) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 012170b1c47a..e5f95c6ab0ac 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1368,15 +1368,17 @@ static __always_inline bool free_pages_prepare(struct page *page, /* * As memory initialization might be integrated into KASAN, - * kasan_free_pages and kernel_init_free_pages must be + * KASAN poisoning and memory initialization code must be * kept together to avoid discrepancies in behavior. * * With hardware tag-based KASAN, memory tags must be set before the * page becomes unavailable via debug_pagealloc or arch_free_page. */ if (kasan_has_integrated_init()) { + bool init = want_init_on_free(); + if (!skip_kasan_poison) - kasan_free_pages(page, order); + kasan_poison_pages(page, order, init); } else { bool init = want_init_on_free(); -- 2.25.1