From patchwork Wed Jan 4 07:43:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Thompson X-Patchwork-Id: 13088238 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A51F9C4708D for ; Wed, 4 Jan 2023 07:50:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233761AbjADHuK (ORCPT ); Wed, 4 Jan 2023 02:50:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233760AbjADHuK (ORCPT ); Wed, 4 Jan 2023 02:50:10 -0500 X-Greylist: delayed 390 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 03 Jan 2023 23:50:08 PST Received: from a27-57.smtp-out.us-west-2.amazonses.com (a27-57.smtp-out.us-west-2.amazonses.com [54.240.27.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E5FC193E9; Tue, 3 Jan 2023 23:50:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=ude52klaz7ukvnrchdbsicqdl2lnui6h; d=aaront.org; t=1672818216; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=drHjpr0LHopx3HmqATFGIrCQSSTGv27hzya8Ew0g6V0=; b=UE067h7LNAsgokFSAm1nEPCePx7WT8g/3bIOD+y6aOOanycNXzF3g6NhqJ+TdMfu Z0dE+5Jf9HY1gf1C0KaIXCKQQNJiZzp8ivVv76+e9lUkq1AmGCqI7XdTaeQahAvQPju M7QpFzzlH4xGPzUIeTqAW60oWuliPe9JERUaJptc= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=gdwg2y3kokkkj5a55z2ilkup5wp5hhxx; d=amazonses.com; t=1672818216; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Feedback-ID; bh=drHjpr0LHopx3HmqATFGIrCQSSTGv27hzya8Ew0g6V0=; b=MPGVIN0AEOZB7CFSj53TUjTMTZg4ynawBP8navibhP2eOfgrQHo4atsokw6fpbCC GgW/16MjUdZi0cWtdJWDhl506FC61j4wNehQP0ThYihw+sPk3Q25fYFet7q0Jb0F8VC MZ9HXdWgTT4yEiRziU6w6idRY0BNZnRlVyeWdmgc= From: Aaron Thompson To: linux-mm@kvack.org, Mike Rapoport Cc: "H. Peter Anvin" , Alexander Potapenko , Andrew Morton , Andy Shevchenko , Ard Biesheuvel , Borislav Petkov , Darren Hart , Dave Hansen , Dmitry Vyukov , Ingo Molnar , Marco Elver , Thomas Gleixner , kasan-dev@googlegroups.com, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org, x86@kernel.org, Aaron Thompson Subject: [PATCH 1/1] mm: Always release pages to the buddy allocator in memblock_free_late(). Date: Wed, 4 Jan 2023 07:43:36 +0000 Message-ID: <010101857bbc4d26-d9683bb4-c4f0-465b-aea6-5314dbf0aa01-000000@us-west-2.amazonses.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230104074215.2621-1-dev@aaront.org> References: <20230104074215.2621-1-dev@aaront.org> MIME-Version: 1.0 Feedback-ID: 1.us-west-2.OwdjDcIoZWY+bZWuVZYzryiuW455iyNkDEZFeL97Dng=:AmazonSES X-SES-Outgoing: 2023.01.04-54.240.27.57 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org If CONFIG_DEFERRED_STRUCT_PAGE_INIT is enabled, memblock_free_pages() only releases pages to the buddy allocator if they are not in the deferred range. This is correct for free pages (as defined by for_each_free_mem_pfn_range_in_zone()) because free pages in the deferred range will be initialized and released as part of the deferred init process. memblock_free_pages() is called by memblock_free_late(), which is used to free reserved ranges after memblock_free_all() has run. memblock_free_all() initializes all pages in reserved ranges, and accordingly, those pages are not touched by the deferred init process. This means that currently, if the pages that memblock_free_late() intends to release are in the deferred range, they will never be released to the buddy allocator. They will forever be reserved. In addition, memblock_free_pages() calls kmsan_memblock_free_pages(), which is also correct for free pages but is not correct for reserved pages. KMSAN metadata for reserved pages is initialized by kmsan_init_shadow(), which runs shortly before memblock_free_all(). For both of these reasons, memblock_free_pages() should only be called for free pages, and memblock_free_late() should call __free_pages_core() directly instead. Fixes: 3a80a7fa7989 ("mm: meminit: initialise a subset of struct pages if CONFIG_DEFERRED_STRUCT_PAGE_INIT is set") Signed-off-by: Aaron Thompson --- mm/memblock.c | 2 +- tools/testing/memblock/internal.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/mm/memblock.c b/mm/memblock.c index 511d4783dcf1..56a5b6086c50 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1640,7 +1640,7 @@ void __init memblock_free_late(phys_addr_t base, phys_addr_t size) end = PFN_DOWN(base + size); for (; cursor < end; cursor++) { - memblock_free_pages(pfn_to_page(cursor), cursor, 0); + __free_pages_core(pfn_to_page(cursor), 0); totalram_pages_inc(); } } diff --git a/tools/testing/memblock/internal.h b/tools/testing/memblock/internal.h index fdb7f5db7308..85973e55489e 100644 --- a/tools/testing/memblock/internal.h +++ b/tools/testing/memblock/internal.h @@ -15,6 +15,10 @@ bool mirrored_kernelcore = false; struct page {}; +void __free_pages_core(struct page *page, unsigned int order) +{ +} + void memblock_free_pages(struct page *page, unsigned long pfn, unsigned int order) {