From mboxrd@z Thu Jan 1 00:00:00 1970 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 DDBB0C3DA7D for ; Thu, 5 Jan 2023 04:02:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3F3C78E0002; Wed, 4 Jan 2023 23:02:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3A3478E0001; Wed, 4 Jan 2023 23:02:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 26BAB8E0002; Wed, 4 Jan 2023 23:02:52 -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 14BBE8E0001 for ; Wed, 4 Jan 2023 23:02:52 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id CA0CF140A6F for ; Thu, 5 Jan 2023 04:02:51 +0000 (UTC) X-FDA: 80319399342.06.CB13B00 Received: from a27-51.smtp-out.us-west-2.amazonses.com (a27-51.smtp-out.us-west-2.amazonses.com [54.240.27.51]) by imf18.hostedemail.com (Postfix) with ESMTP id E0A571C0008 for ; Thu, 5 Jan 2023 04:02:49 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=aaront.org header.s=ude52klaz7ukvnrchdbsicqdl2lnui6h header.b=A2eIR5Z+; dkim=pass header.d=amazonses.com header.s=gdwg2y3kokkkj5a55z2ilkup5wp5hhxx header.b=BsiWU+dJ; spf=pass (imf18.hostedemail.com: domain of 01010185801881b4-2dd5c952-d967-414b-9dc6-7edb04436342-000000@ses-us-west-2.bounces.aaront.org designates 54.240.27.51 as permitted sender) smtp.mailfrom=01010185801881b4-2dd5c952-d967-414b-9dc6-7edb04436342-000000@ses-us-west-2.bounces.aaront.org; dmarc=pass (policy=quarantine) header.from=aaront.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1672891370; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=EwW7mhioEl6+pqxpuJNZ/UvndZUxFCljFPe17HDDkoU=; b=NNNK1K5XghFyp8LsCVL/V13B/+YEzM1O+nXFIw9GHxNl0qwAKubzyhLxytTR52s1jW65Z9 8GLWYeOT+H5gettY3kYJq4GxwO+4V4vZzY770l1YWJlp/Hk4dgPE7GlJQQH+vHB06/Xbdr hr/WMWN7uBR7WBy5Ua6xwS4D6xvktP4= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=aaront.org header.s=ude52klaz7ukvnrchdbsicqdl2lnui6h header.b=A2eIR5Z+; dkim=pass header.d=amazonses.com header.s=gdwg2y3kokkkj5a55z2ilkup5wp5hhxx header.b=BsiWU+dJ; spf=pass (imf18.hostedemail.com: domain of 01010185801881b4-2dd5c952-d967-414b-9dc6-7edb04436342-000000@ses-us-west-2.bounces.aaront.org designates 54.240.27.51 as permitted sender) smtp.mailfrom=01010185801881b4-2dd5c952-d967-414b-9dc6-7edb04436342-000000@ses-us-west-2.bounces.aaront.org; dmarc=pass (policy=quarantine) header.from=aaront.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1672891370; a=rsa-sha256; cv=none; b=r49EBJFw5H8j8KgDZMrxx202zbvBmUnc2bCrJ/BN0Cin+YLPj8eu7yhLvOcruCcb/3veA5 T+TpUe2ScxFPjwepM6tP7ZaH34BHcVOVwq6SabakQP6MS5s/k8uUNtA1wNv7jES4pmXw0z wWb4MCBPtghgk4ypYJm3rn1i8W2TWHQ= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=ude52klaz7ukvnrchdbsicqdl2lnui6h; d=aaront.org; t=1672891368; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References:Message-ID:Content-Type:Content-Transfer-Encoding; bh=UaVZxhaholgYXRv1rnjX2lEzJ1yj5wIkBR8OS8N2qdE=; b=A2eIR5Z+ZuwTZpmlUW6p3X7w1442qVqEfxphxcVa4f8BWgZS0GCAeSQGiy9WoZnw mcQpE4Qu9yWk9uVQ5MWvV4mNWWf+rDULMlHvYdFTRmabXYTd4L0gws9010zGZxX5hin fPHaRGjS4NAX5B1Yl9o/wrTepjvNri3mgKf3dvH0= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=gdwg2y3kokkkj5a55z2ilkup5wp5hhxx; d=amazonses.com; t=1672891368; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References:Message-ID:Content-Type:Content-Transfer-Encoding:Feedback-ID; bh=UaVZxhaholgYXRv1rnjX2lEzJ1yj5wIkBR8OS8N2qdE=; b=BsiWU+dJSpdLMh9mVDhNN5url3xV6w8RpkkvzVRJJjx8wL3BwOJJl5m7wmd1ikJZ zu9baddo9xz4TCGrCiVOvr5I7X9kChQH+9haBjHMpUFWMNW064IG+KHd5YgBxTUfIdJ EO1D4OH5rLYYcS/x4VpkzScGIMFt3SzjPuZFTMRY= MIME-Version: 1.0 Date: Thu, 5 Jan 2023 04:02:47 +0000 From: Aaron Thompson To: Mike Rapoport Cc: linux-mm@kvack.org, "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 Subject: Re: [PATCH 1/1] mm: Always release pages to the buddy allocator in memblock_free_late(). In-Reply-To: References: <20230104074215.2621-1-dev@aaront.org> <010101857bbc4d26-d9683bb4-c4f0-465b-aea6-5314dbf0aa01-000000@us-west-2.amazonses.com> User-Agent: Roundcube Webmail/1.4.13 Message-ID: <01010185801881b4-2dd5c952-d967-414b-9dc6-7edb04436342-000000@us-west-2.amazonses.com> X-Sender: dev@aaront.org Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Feedback-ID: 1.us-west-2.OwdjDcIoZWY+bZWuVZYzryiuW455iyNkDEZFeL97Dng=:AmazonSES X-SES-Outgoing: 2023.01.05-54.240.27.51 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: E0A571C0008 X-Stat-Signature: 9k5kyxcefdprah718xwr96a4nx9mfiqr X-Rspam-User: X-HE-Tag: 1672891369-803193 X-HE-Meta: U2FsdGVkX18Yt3BK5K466dGOdH5HlkgOlgWyGZpRk/aDgxnL7d1GZmIdXcsHuqz9mlxKKxWy7ynzLarmjVZG4eZI0bdV79DLYkRiYMHGkjcWGaULcxJSJYZ+TuiTbjhLHKJANLMg7CaP7b9N57s4ylC0ZCCxh1oawSC84ZsIBSEoRYVpJvUGJMj7Xt5JGb+u1ak9v9yRgar65VTahPJcX98+FitpDIu+npczfzj8fV69nsMXytAmJ1SV5WiyfLpgrZzxuDIVXQ7J3deq2c9Lc0Rk5qtxHqkZLdpGuMugR9h3tSC2orh7D7YHbZsrD2xOpYnb0goF7nS1mz9O0rEk6oYmx+jVL3mVlpblA2WUtWb3a7e6AaP/VgbvK2FcjNtL+m+118z/RPe2cAnGQM3RtOQWmuYe/+91M/wG8V+CYsFJ9conLnYFOeGh6BNfTDC/wjLRfyfy0vUQO0C52YXwGCxAfCuJ8QS8XqNycrE7ZVMRzI3A6z1z5C70p8JWtqEOGsCw0B5ZiDTi3ugeA+76kcS0X8ulzTTXq0aQBRb0c2PtqINc8f4HjDh940jBzmJeaa4u/mKLCDDyZYC8TkEVQ4N278yyutj3fFiun4AxDl7PVBKz/uSZ69dKZ37GVChX3+u1Xn7fguDdCReAjH0wrrFn2WIZ3sFPuHJ90Bl2RLfW8CqTsjyks4cWq1XiCD939eKyt5k2W69Jof3cUu1lPrfa43PoqYT49qkwn982aSfSXtdaz/VDXrB05IkSRdld4DIjglwHfetpNS6sjbUqI/+2lZhItCseAVky6V8mvfY+ndHGbCGQoryDLq9OOIhso5FAQMWDO4N2kG08172F7p2yIfnqw9lr2b7d+34tvLcDOnxbTis+w9Ur3WIAk17L1+9z6zOUfMi+WB/ZCBP4BnRsQpwceEc0JEwqbmp0tZ+cn8YN+g18AEcRZWa9E0QL+7rxnTVuQx0FI2dB0n3 XVanLJpO qygRphD/6rK3dSJTLi/WJjdWx/4vtg6vvPvnnkdjl17qhfh7qRTL2CSywH9QfuEAkdZM0HVM9HG1eHJOqJxyvu2Msu8DhgDwDYtvtBnl46Wlww5Dxlays6FMtsVpzjql3QtGba8j3cMBAFRNyYzrpVxmNC4N+VGOdoGkkX9mtaFMUEpHw7gNpxLl6m67U7eFVLbS38QoxHyuf5if3Rl6frvxx4J7FHL9bzS+SyWhao0+nRw21CzkGx1veoP/HJcsY2vM0SOcajrpDYKsuMYvoGic9+fqIxnCGhafTHki5/1k4n9iahwZdxvdHqM4Mq8ys8kjyDggRhNh+qyOy56tq9w5fBL15QEL+Wp/C+dtI1b704MG65IeSH4nMRP6KrhETMY+YfudDs7LNarw= 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: Hi Mike, On 2023-01-04 11:34, Mike Rapoport wrote: > Hi, > > On Wed, Jan 04, 2023 at 07:43:36AM +0000, Aaron Thompson wrote: >> 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 > > To be precise, memblock_free_all() frees pages, or releases them to the > pages allocator, rather than initializes. As you mentioned in the comment below, whether memblock_free_all() does any initializing depends on the particular deferred init situation. memblock_free_all() does ultimately call init_reserved_page() for every reserved page (via reserve_bootmem_region()), but that only actually initializes the page if it's in the deferred range. In either case, all I was trying to say here is that we can be certain that all reserved pages have been initialized after memblock_free_all() has run, so I'll rephrase that. >> 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. > > Overall looks fine to me and I couldn't spot potential issues. > > I'd appreciate if you add a paragraph about the actual issue with EFI > boot > you described in the cover letter to the commit message. Sure, will do. >> 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); > > Please add a comment that explains why it is safe to call > __free_pages_core() here. > Something like > > /* > * Reserved pages are always initialized by the end of > * memblock_free_all() either during memmap_init() or, with deferred > * initialization if struct page in reserve_bootmem_region() > */ Will do. Thanks for the review. >> 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) >> { >> -- >> 2.30.2 >> Thanks, -- Aaron