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 5FACFC0015E for ; Sat, 29 Jul 2023 08:13:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8C36D8D0002; Sat, 29 Jul 2023 04:12:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 873938D0001; Sat, 29 Jul 2023 04:12:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 762918D0002; Sat, 29 Jul 2023 04:12:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 631848D0001 for ; Sat, 29 Jul 2023 04:12:59 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 304CD16039D for ; Sat, 29 Jul 2023 08:12:59 +0000 (UTC) X-FDA: 81063933678.29.3C33F8F Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf15.hostedemail.com (Postfix) with ESMTP id 7CA42A0006 for ; Sat, 29 Jul 2023 08:12:57 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ffmbrV2O; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf15.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690618377; a=rsa-sha256; cv=none; b=kZcSmIaaKGhci3/OOr/ynvlBP02ituFjvyqkBA2n4ZV3Nyy/1LTf8VAqddkV723ZpgkAOZ a7ZNgJzD6lcOXxl70EzGeDphc3250mbPZmGTOYDQz5NRzkyxAcKVZAyXeFHf7nt2nRf69F o3HQeRlVS2O45oj9cDuT4BbKqP+eoFU= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ffmbrV2O; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf15.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690618377; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=s+bSMfJRv5kwuIyoP48qCaTikvXV3wj5VGnaQ3C7Rhk=; b=Q6Ao9g5yf85lw/mO4zmtnjmMO8nlXXFZmEIJU5MUUNpmlKGPx//Ym2TMAfVPLU3ZHG0u+B wEyHlsPlvo2C3IrfH7XgTrEV1TU5UkbSaGK9T0WgqSxogjFfnWJegjZt7HPwWZrZnKFUyl VdwYDVMzaTr/LPdE34nyu1yTCqYGhEA= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6562960A1A; Sat, 29 Jul 2023 08:12:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50227C433C7; Sat, 29 Jul 2023 08:12:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690618375; bh=KhrkYsVR8h1RX7EdJAeZS6DnvY+gj2yvvKx4ay7ZYGU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ffmbrV2OYYapB9oKLE2nU8YWZCR4xmHdf6Bv0n3yOIvh2OxH+OY4OSgG00lUHp0M5 XK/FngXMoXQJo5/Ucf9EcfIR8kW/q1DMQxshafjDvSWVaWycvfTJnggs0a+JbN75Rl QnZVLdBUkeX2uAEpl4zr4oRHDxfhm9Bt4gpOu1nk7fwKrbnnSht+qAVQcwd6or12N2 6MXqzWE/Z5NYRxQ4vD3GHZOh78hmKGVEqcZ2GO9iOTGv0wrd2qxd33+H9A+MX9Sb8H T5QrTVSGmhmrUXDo8vF9VpCKCLYtgGn6fcVSJm9xvhfoGW70DUcIjQ95JhB9uvSoni /VnvpjPwfLAeg== Date: Sat, 29 Jul 2023 11:12:18 +0300 From: Mike Rapoport To: Wupeng Ma Cc: akpm@linux-foundation.org, linux-mm@kvack.org Subject: Re: [PATCH] mm: disable kernelcore=mirror when no mirror memory Message-ID: <20230729081218.GH1901145@kernel.org> References: <20230728040124.4093229-1-mawupeng1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230728040124.4093229-1-mawupeng1@huawei.com> X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 7CA42A0006 X-Stat-Signature: ik41rpb6z7aborykutdtiafibr4qpmse X-HE-Tag: 1690618377-861949 X-HE-Meta: U2FsdGVkX192anhjKIU+pPQERV9JapWGIEagCwGBwbq75pXcw8O4kEQBwZOiNxbOsY/ouGlX4pAR8tQioKrEpByVCbd2m3uCU+J4GguX+ojT4CbCC/K5E4H/9eFImeHobEsejrLWOmFFRYx5NpRTeCa8sLU3yysE7mQGTLSyDmKngUcK5uIWyjeUXSCrM/76srzpLe2gJdyZ84OPXLbLiSPk8K4CFNhB9RXjMgXTfyjhQtThdbUEFrE29q47xLtMWnoG+pqXPupcdjhykPuW0Ic5O2hO4UjBkUpd6ioRi6eCQzpzkY9Cj6h33EokxOJE/Q8ua0ReRHGfi6UE/CS32XlQpDmvAJgJA7Hp5PBZjf0r9ncbXhkc5qtqidgxOBdBpRQ0oHkYroK+rjnCBpxz+laJNApv/R2pV9CtXnSV6q+niXtP+Prt06QEBusWR4NQdL2FyITxn/ZIF9EwZtmGsy/p/quudKpgKJ09NQcUOkhbtW/AVfa2HZqqPXgRs5id0vaRvrAunKIkK9VTNtIXkeDcU3MgHE6gUbNKmJU4Yi49+q97m3xlRzKQrDDt3YkeP6cK7fMd367vU+2DhknBpmVSP+NJht0xht4nd7l3lva9LDOCVzTfUa0+xsOqh1+QV3im1lMuSNjfn4OPt+fk0rwnqfKZk44rl4QCpoB+n4iIQ6ahUIB4RuQQcn/KD/kpDmF6Udqsq9NTggEYnHRa1zWt4i0VA8nR3vRoYdQS6U8iMu9D+q97ysq6ExglLC5gzsCzYFRbnnauKpr3djkcHbOVLLpDsK4T6gtlf/1To/+Ok9ZVXJ2MKdtDYKNny6pFqDcBkg98hYGC9j4g/ASyTJPH7s7SZD47N/wZOpc2zoHxgn/oc7qPry/3nbQXBZu/KIDllHEmgI0eIJrxU+TLieDHtrnxDHW6PKc9A7FGGlgfUyj5I2Rk+nC/rRm4jRv7Uwhc3ZN7h8i3NF7RiyO nwaElgow 9H4/9BRKc39qUS/YCiq9jLeiA8z8RB3RAS2brJPk6fm1p19uwEA3QS/yB78n8SYEMU8gxLxuwKLZ+oOSscEuh/BFOG09I/xvdlQ6N16xdkUIeWoNF8EigWBxcqtzemN6xMD3uiBoYSfvuPPNFXSzwwZGxrLryhXACp6q6N6li8U78DEFIcXo0iQDc1UF8xzXhwlwgC48n0KLfu1jvUU64clZghbi2tFPxmgLE24LHNX6Gh6AUnNS/65HMA51NZJn9rn2kNxixNtNgO6bYW0XeK+tCwjV2AJZiKNXnq/u0cWWbzFjCeNGSo8yx1g== 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: On Fri, Jul 28, 2023 at 12:01:24PM +0800, Wupeng Ma wrote: > From: Ma Wupeng > > For system with kernelcore=mirror enabled while no mirrored memory is > reported by efi. This could lead to kernel OOM during startup since > all memory beside zone DMA are in the movable zone and this prevents > the kernel to use it. > > Zone DMA/DMA32 initialization is independent of mirrored memory and > their max pfn is set in zone_sizes_init(). Since kernel can fallback > to zone DMA/DMA32 if there is no memory in zone Normal, these zones > are seen as mirrored memory no mather their memory attributes are. Using kernelcore= and movablecore= always come with the risk there will be to little memory for the kernel to use. Even if EFI reports mirrored memory it's possible to have OOM with kernelcore=mirror because there could be just not enough mirrored memory. > To solve this problem, disable kernelcore=mirror when there is no real > mirrored memory exists. > > Signed-off-by: Ma Wupeng > --- > mm/internal.h | 2 ++ > mm/memblock.c | 2 +- > mm/mm_init.c | 6 +++++- > 3 files changed, 8 insertions(+), 2 deletions(-) > > diff --git a/mm/internal.h b/mm/internal.h > index a7d9e980429a..98a03ac74ca7 100644 > --- a/mm/internal.h > +++ b/mm/internal.h > @@ -374,6 +374,8 @@ static inline void clear_zone_contiguous(struct zone *zone) > zone->contiguous = false; > } > > +extern bool system_has_some_mirror; > + > extern int __isolate_free_page(struct page *page, unsigned int order); > extern void __putback_isolated_page(struct page *page, unsigned int order, > int mt); > diff --git a/mm/memblock.c b/mm/memblock.c > index f9e61e565a53..e7a7a65415fb 100644 > --- a/mm/memblock.c > +++ b/mm/memblock.c > @@ -156,10 +156,10 @@ static __refdata struct memblock_type *memblock_memory = &memblock.memory; > } while (0) > > static int memblock_debug __initdata_memblock; > -static bool system_has_some_mirror __initdata_memblock; > static int memblock_can_resize __initdata_memblock; > static int memblock_memory_in_slab __initdata_memblock; > static int memblock_reserved_in_slab __initdata_memblock; > +bool system_has_some_mirror __initdata_memblock; > > static enum memblock_flags __init_memblock choose_memblock_flags(void) > { > diff --git a/mm/mm_init.c b/mm/mm_init.c > index a1963c3322af..6267b9f75927 100644 > --- a/mm/mm_init.c > +++ b/mm/mm_init.c > @@ -269,7 +269,11 @@ static int __init cmdline_parse_kernelcore(char *p) > { > /* parse kernelcore=mirror */ > if (parse_option_str(p, "mirror")) { > - mirrored_kernelcore = true; > + if (system_has_some_mirror) > + mirrored_kernelcore = true; On many architectures early parameters are parsed before memblock is setup, so system_has_some_mirror will always be true. > + else > + pr_warn("The system has no mirror memory, disable kernelcore=mirror.\n"); > + > return 0; > } > > -- > 2.25.1 > -- Sincerely yours, Mike.