From patchwork Mon Sep 21 12:05:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anshuman Khandual X-Patchwork-Id: 11789621 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 62092618 for ; Mon, 21 Sep 2020 12:06:27 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 004E72151B for ; Mon, 21 Sep 2020 12:06:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="2M/tJ0li" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 004E72151B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:To: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=V81gVz7BiYNzenLs2BNM/Idn7jvtyo930oMuT0+UjhQ=; b=2M/tJ0liYCKuqCEtOQaWNicCDb 1X8nJ+0CCxOcwvEXl52QASGhC/nTARxLatAEMK60v1LP1WRZ+kQIDKsLgPxSsKHITULK8yeYdfamy We/wCti06wupqU9vqE+PjGT7NYM+Xor5mQNrIQpQIKiby2nNdgHlJSGlotWnxg4GuBOQ1kaken89n 1+NFEN9dq4btjinVu0rjlweLRLpftjtOWDUX145QNhaa2xb3BqMwilRtgKR8P7xEWp3I3B4KJqT/G 2BFPjzoiTlBgZNdmL4gacitR7BzqtuxpSaQVolZNOL7Vk0tecoAeu5HezK15/wLZS8g6r569+Ki+m NyJnPp5w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kKKaD-0005RP-Kr; Mon, 21 Sep 2020 12:06:13 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kKKa2-0005NU-N9 for linux-arm-kernel@lists.infradead.org; Mon, 21 Sep 2020 12:06:03 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 537151063; Mon, 21 Sep 2020 05:06:02 -0700 (PDT) Received: from p8cg001049571a15.arm.com (unknown [10.163.75.158]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C06B93F73B; Mon, 21 Sep 2020 05:05:58 -0700 (PDT) From: Anshuman Khandual To: linux-arm-kernel@lists.infradead.org Subject: [PATCH V3 1/3] arm64/mm/hotplug: Register boot memory hot remove notifier earlier Date: Mon, 21 Sep 2020 17:35:06 +0530 Message-Id: <1600689908-28213-2-git-send-email-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1600689908-28213-1-git-send-email-anshuman.khandual@arm.com> References: <1600689908-28213-1-git-send-email-anshuman.khandual@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200921_080602_823005_C3538E2F X-CRM114-Status: GOOD ( 16.35 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [217.140.110.172 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Will Deacon , Anshuman Khandual , catalin.marinas@arm.com, Steve Capper , linux-kernel@vger.kernel.org, Mark Brown , Marc Zyngier , will@kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org This moves memory notifier registration earlier in the boot process from device_initcall() to early_initcall() which will help in guarding against potential early boot memory offline requests. Even though there should not be any actual offlinig requests till memory block devices are initialized with memory_dev_init() but then generic init sequence might just change in future. Hence an early registration for the memory event notifier would be helpful. While here, just skip the registration if CONFIG_MEMORY_HOTREMOVE is not enabled and also call out when memory notifier registration fails. Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Rutland Cc: Marc Zyngier Cc: Steve Capper Cc: Mark Brown Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Anshuman Khandual Reviewed-by: Gavin Shan --- arch/arm64/mm/mmu.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 75df62fea1b6..df3b7415b128 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -1499,7 +1499,17 @@ static struct notifier_block prevent_bootmem_remove_nb = { static int __init prevent_bootmem_remove_init(void) { - return register_memory_notifier(&prevent_bootmem_remove_nb); + int ret = 0; + + if (!IS_ENABLED(CONFIG_MEMORY_HOTREMOVE)) + return ret; + + ret = register_memory_notifier(&prevent_bootmem_remove_nb); + if (!ret) + return ret; + + pr_err("Notifier registration failed - boot memory can be removed\n"); + return ret; } -device_initcall(prevent_bootmem_remove_init); +early_initcall(prevent_bootmem_remove_init); #endif From patchwork Mon Sep 21 12:05:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anshuman Khandual X-Patchwork-Id: 11789625 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A69F66CB for ; Mon, 21 Sep 2020 12:07:56 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 654A4216C4 for ; Mon, 21 Sep 2020 12:07:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="JdjPmjn1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 654A4216C4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:To: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=cEL+UPF6PGSSFWOS2VK3lv8ET3OLh9yCDUdhTxKwMys=; b=JdjPmjn1EzEuhvoqhByJY1XSzo +zg0E6ZvV05+rSDSASEVx0lNcL+9Gwmox5muFJvD+QKF5Pz7USkAYRkzuzUgpejB7JGP21zDJNYcM UR5fzofp7T3UHT/R5EAYtnsMJV1fwMwGq33kxJg+Aet2JRFNcyGTFq2DtEBR3muyeZOE3a85/vgX6 jwDLNlLKnsWl0Tz8u+N8/fOMrAm9KbK5t3ZizdHD4OcGefm0ocQQr4hiTpfi1/s0/GYq7ey6HaDhR gPI+vqGY6H8Fl7BUzEjzcKr0hR9KTNWFxPkoOxdeWKGLi8+DWH5QZzQIdz9x2/7xoCxRkbMN5MH+b ZC2ranSA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kKKaJ-0005TF-83; Mon, 21 Sep 2020 12:06:19 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kKKa7-0005PO-Kv for linux-arm-kernel@lists.infradead.org; Mon, 21 Sep 2020 12:06:09 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A7E6AD6E; Mon, 21 Sep 2020 05:06:06 -0700 (PDT) Received: from p8cg001049571a15.arm.com (unknown [10.163.75.158]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id F19A23F73B; Mon, 21 Sep 2020 05:06:02 -0700 (PDT) From: Anshuman Khandual To: linux-arm-kernel@lists.infradead.org Subject: [PATCH V3 2/3] arm64/mm/hotplug: Enable MEM_OFFLINE event handling Date: Mon, 21 Sep 2020 17:35:07 +0530 Message-Id: <1600689908-28213-3-git-send-email-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1600689908-28213-1-git-send-email-anshuman.khandual@arm.com> References: <1600689908-28213-1-git-send-email-anshuman.khandual@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200921_080608_212697_B441CC5D X-CRM114-Status: GOOD ( 17.11 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [217.140.110.172 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Will Deacon , Anshuman Khandual , catalin.marinas@arm.com, Steve Capper , linux-kernel@vger.kernel.org, Mark Brown , Marc Zyngier , will@kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org This enables MEM_OFFLINE memory event handling. It will help intercept any possible error condition such as if boot memory some how still got offlined even after an explicit notifier failure, potentially by a future change in generic hot plug framework. This would help detect such scenarios and help debug further. Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Rutland Cc: Marc Zyngier Cc: Steve Capper Cc: Mark Brown Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Anshuman Khandual --- arch/arm64/mm/mmu.c | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index df3b7415b128..6b171bd88bcf 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -1482,13 +1482,40 @@ static int prevent_bootmem_remove_notifier(struct notifier_block *nb, unsigned long end_pfn = arg->start_pfn + arg->nr_pages; unsigned long pfn = arg->start_pfn; - if (action != MEM_GOING_OFFLINE) + if ((action != MEM_GOING_OFFLINE) && (action != MEM_OFFLINE)) return NOTIFY_OK; - for (; pfn < end_pfn; pfn += PAGES_PER_SECTION) { - ms = __pfn_to_section(pfn); - if (early_section(ms)) - return NOTIFY_BAD; + if (action == MEM_GOING_OFFLINE) { + for (; pfn < end_pfn; pfn += PAGES_PER_SECTION) { + ms = __pfn_to_section(pfn); + if (early_section(ms)) { + pr_warn("Boot memory offlining attempted\n"); + return NOTIFY_BAD; + } + } + } else if (action == MEM_OFFLINE) { + for (; pfn < end_pfn; pfn += PAGES_PER_SECTION) { + ms = __pfn_to_section(pfn); + if (early_section(ms)) { + + /* + * This should have never happened. Boot memory + * offlining should have been prevented by this + * very notifier. Probably some memory removal + * procedure might have changed which would then + * require further debug. + */ + pr_err("Boot memory offlined\n"); + + /* + * Core memory hotplug does not process a return + * code from the notifier for MEM_OFFLINE event. + * Error condition has been reported. Report as + * ignored. + */ + return NOTIFY_DONE; + } + } } return NOTIFY_OK; } From patchwork Mon Sep 21 12:05:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anshuman Khandual X-Patchwork-Id: 11789623 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AD9796CA for ; Mon, 21 Sep 2020 12:06:44 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6E4D4216C4 for ; Mon, 21 Sep 2020 12:06:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="afw0EkdP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6E4D4216C4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:To: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ZNbZxbh15J5WPsbS8NmZbox5g2KvYHFHHHkzefQa8E4=; b=afw0EkdPZFUSIgjcEuYaPiUlH+ MU4n4kBzCeh0OFQB5h6AjbbPjzvU6HRn4wsKgAddZec32dUkue+gjL91CLUWRl4hHxBVKRFL80yCZ lsjeE8dAuZNRRWK2aU5CATWbfqBqgzom//vEjFWBKKH48qO9HLyIcq4OtVMtBQLjXQmEb2nqzIh/X BfzGolkPFFzBsfhtGAHlZWUgYFiRLmfGJfLiGCo/z8HQ4e9dTIoYcyOfa+X1D2KxUH5pzwKV5REwM p2FiFAXZ65fVAcpSnpSP01KqQRgs3XUpu1EUAW9p64h0y1x+0Kapeedl0hicIwohwACo4VJ3pz67j yAJhZ5OA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kKKaW-0005Y5-EZ; Mon, 21 Sep 2020 12:06:32 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kKKaB-0005Qj-LQ for linux-arm-kernel@lists.infradead.org; Mon, 21 Sep 2020 12:06:13 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 68BB71063; Mon, 21 Sep 2020 05:06:10 -0700 (PDT) Received: from p8cg001049571a15.arm.com (unknown [10.163.75.158]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 461DB3F73B; Mon, 21 Sep 2020 05:06:06 -0700 (PDT) From: Anshuman Khandual To: linux-arm-kernel@lists.infradead.org Subject: [PATCH V3 3/3] arm64/mm/hotplug: Ensure early memory sections are all online Date: Mon, 21 Sep 2020 17:35:08 +0530 Message-Id: <1600689908-28213-4-git-send-email-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1600689908-28213-1-git-send-email-anshuman.khandual@arm.com> References: <1600689908-28213-1-git-send-email-anshuman.khandual@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200921_080611_821315_0B7CAA8C X-CRM114-Status: GOOD ( 21.34 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [217.140.110.172 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Will Deacon , Anshuman Khandual , catalin.marinas@arm.com, Steve Capper , linux-kernel@vger.kernel.org, Mark Brown , Marc Zyngier , will@kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org This adds a validation function that scans the entire boot memory and makes sure that all early memory sections are online. This check is essential for the memory notifier to work properly, as it cannot prevent any boot memory from offlining, if all sections are not online to begin with. The notifier registration is skipped, if this validation does not go through. Although the boot section scanning is selectively enabled with DEBUG_VM. Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Rutland Cc: Marc Zyngier Cc: Steve Capper Cc: Mark Brown Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Anshuman Khandual --- arch/arm64/mm/mmu.c | 59 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 6b171bd88bcf..124eeb84ec43 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -1524,6 +1524,62 @@ static struct notifier_block prevent_bootmem_remove_nb = { .notifier_call = prevent_bootmem_remove_notifier, }; +/* + * This ensures that boot memory sections on the plaltform are online + * during early boot. They could not be prevented from being offlined + * if for some reason they are not brought online to begin with. This + * help validate the basic assumption on which the above memory event + * notifier works to prevent boot memory offlining and it's possible + * removal. + */ +static bool validate_bootmem_online(void) +{ + struct memblock_region *mblk; + struct mem_section *ms; + unsigned long pfn, end_pfn, start, end; + bool all_online = true; + + /* + * Scanning across all memblock might be expensive + * on some big memory systems. Hence enable this + * validation only with DEBUG_VM. + */ + if (!IS_ENABLED(CONFIG_DEBUG_VM)) + return all_online; + + for_each_memblock(memory, mblk) { + pfn = PHYS_PFN(mblk->base); + end_pfn = PHYS_PFN(mblk->base + mblk->size); + + for (; pfn < end_pfn; pfn += PAGES_PER_SECTION) { + ms = __pfn_to_section(pfn); + + /* + * All memory ranges in the system at this point + * should have been marked early sections. + */ + WARN_ON(!early_section(ms)); + + /* + * Memory notifier mechanism here to prevent boot + * memory offlining depends on the fact that each + * early section memory on the system is intially + * online. Otherwise a given memory section which + * is already offline will be overlooked and can + * be removed completely. Call out such sections. + */ + if (!online_section(ms)) { + start = PFN_PHYS(pfn); + end = start + (1UL << PA_SECTION_SHIFT); + pr_err("Memory range [%lx %lx] is offline\n", start, end); + pr_err("Memory range [%lx %lx] can be removed\n", start, end); + all_online = false; + } + } + } + return all_online; +} + static int __init prevent_bootmem_remove_init(void) { int ret = 0; @@ -1531,6 +1587,9 @@ static int __init prevent_bootmem_remove_init(void) if (!IS_ENABLED(CONFIG_MEMORY_HOTREMOVE)) return ret; + if (!validate_bootmem_online()) + return -EINVAL; + ret = register_memory_notifier(&prevent_bootmem_remove_nb); if (!ret) return ret;