From patchwork Thu Jun 16 12:00:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Ellerman X-Patchwork-Id: 12883765 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 CC837C433EF for ; Thu, 16 Jun 2022 12:00:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E90D16B0072; Thu, 16 Jun 2022 08:00:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E3F646B0073; Thu, 16 Jun 2022 08:00:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D07B66B0074; Thu, 16 Jun 2022 08:00:51 -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 C20196B0072 for ; Thu, 16 Jun 2022 08:00:51 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5554321717 for ; Thu, 16 Jun 2022 12:00:51 +0000 (UTC) X-FDA: 79583957502.25.BF1BD9B Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by imf10.hostedemail.com (Postfix) with ESMTP id 3006EC008C for ; Thu, 16 Jun 2022 12:00:50 +0000 (UTC) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4LP1315Bqbz4xXg; Thu, 16 Jun 2022 22:00:45 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1655380846; bh=jo/dV6iysmKe/fZZWEHdT+d49Xg4lss23KkkOTxWzCw=; h=From:To:Cc:Subject:Date:From; b=YO2PFQuBET/GKK+gcvRFXux0H3oW8lIDa8SjW/7On3oGYGxWMdRz41N350W/+2oFc VCbUig6C8RkJfy03vYNTzL37cLnIrxysRKNs7GgtjKlGmOtlqqHy/65M0bx8AHOUn1 5DPyoTalqdKyWkV8nqHIdQOaqOcPByZnncsOdG9JFxsHjnhcj4zzH+kFx0+J1MmFjD TAupWYX5B6/cJPVEGuR8DrusZaM7viQwgR5fVKVTBaf5G46flnzvgdcoLF6H+EHCFY Ic1lVs0wS7SdjjF/7LZ1DMYjIQZEB4FDBr/btXFrB4ShvXSpnySgGzE4pMwuBWHnI+ KA6d7YZXecrsA== From: Michael Ellerman To: Cc: , ziy@nvidia.com, Subject: [PATCH] powerpc/mm: Move CMA reservations after initmem_init() Date: Thu, 16 Jun 2022 22:00:33 +1000 Message-Id: <20220616120033.1976732-1-mpe@ellerman.id.au> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655380851; a=rsa-sha256; cv=none; b=vSLdq0EFfQrH+JS285beLBHIGorxwSY9A05uaaUQhM5PMkQBs5//MjahwLXyxA3d//mmqb MN7QNdZChwYBrlaXBB2ehwEBWbbn0hn5+CsG7EUNsXx0gbCwtzKZ9zltl47a6C/BYb8pGZ ykjDNulqSW0Ns3UGW7uQExzpMmdvoek= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=ellerman.id.au header.s=201909 header.b=YO2PFQuB; dmarc=none; spf=pass (imf10.hostedemail.com: domain of michael@ellerman.id.au designates 150.107.74.76 as permitted sender) smtp.mailfrom=michael@ellerman.id.au ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655380851; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=jo/dV6iysmKe/fZZWEHdT+d49Xg4lss23KkkOTxWzCw=; b=L6VNjH4ZbUzthKFopyxibRxGlaJWUzccko0mL7obmVC5LvHoVPsw858no4MeCjhHYRM9Eb yVJKTMR7+IdcsB+P6gD2AW0CD0q5lB7wSSM7uFqWFbIaycyMNnRLiE6KJLwIla6T9p7djW KJo+9NKIwyOa16MpMYD2XBBgdFAKUyw= Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=ellerman.id.au header.s=201909 header.b=YO2PFQuB; dmarc=none; spf=pass (imf10.hostedemail.com: domain of michael@ellerman.id.au designates 150.107.74.76 as permitted sender) smtp.mailfrom=michael@ellerman.id.au X-Rspam-User: X-Stat-Signature: fsfuap1qiu7o3or8ew4mafj7cfbtjmme X-Rspamd-Queue-Id: 3006EC008C X-Rspamd-Server: rspam08 X-HE-Tag: 1655380850-601641 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000013, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: After commit 11ac3e87ce09 ("mm: cma: use pageblock_order as the single alignment") there is an error at boot about the KVM CMA reservation failing, eg: kvm_cma_reserve: reserving 6553 MiB for global area cma: Failed to reserve 6553 MiB That makes it impossible to start KVM guests using the hash MMU with more than 2G of memory, because the VM is unable to allocate a large enough region for the hash page table, eg: $ qemu-system-ppc64 -enable-kvm -M pseries -m 4G ... qemu-system-ppc64: Failed to allocate KVM HPT of order 25: Cannot allocate memory Aneesh pointed out that this happens because when kvm_cma_reserve() is called, pageblock_order has not been initialised yet, and is still zero, causing the checks in cma_init_reserved_mem() against CMA_MIN_ALIGNMENT_PAGES to fail. Fix it by moving the call to kvm_cma_reserve() after initmem_init(). The pageblock_order is initialised in sparse_init() which is called from initmem_init(). Also move the hugetlb CMA reservation. Fixes: 11ac3e87ce09 ("mm: cma: use pageblock_order as the single alignment") Signed-off-by: Michael Ellerman Reviewed-by: Aneesh Kumar K.V Reviewed-by: Zi Yan --- arch/powerpc/kernel/setup-common.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/kernel/setup-common.c b/arch/powerpc/kernel/setup-common.c index eb0077b302e2..1a02629ec70b 100644 --- a/arch/powerpc/kernel/setup-common.c +++ b/arch/powerpc/kernel/setup-common.c @@ -935,12 +935,6 @@ void __init setup_arch(char **cmdline_p) /* Print various info about the machine that has been gathered so far. */ print_system_info(); - /* Reserve large chunks of memory for use by CMA for KVM. */ - kvm_cma_reserve(); - - /* Reserve large chunks of memory for us by CMA for hugetlb */ - gigantic_hugetlb_cma_reserve(); - klp_init_thread_info(&init_task); setup_initial_init_mm(_stext, _etext, _edata, _end); @@ -955,6 +949,13 @@ void __init setup_arch(char **cmdline_p) initmem_init(); + /* + * Reserve large chunks of memory for use by CMA for KVM and hugetlb. These must + * be called after initmem_init(), so that pageblock_order is initialised. + */ + kvm_cma_reserve(); + gigantic_hugetlb_cma_reserve(); + early_memtest(min_low_pfn << PAGE_SHIFT, max_low_pfn << PAGE_SHIFT); if (ppc_md.setup_arch)