Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp26593ybg; Mon, 27 Jul 2020 22:15:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJzwZuUCi8OZDd5+TvwHUZRLcWjpc64+6F9KiTkLKHYfbZHhyCRpgjGDkVL/4bVelXFC7S X-Received: by 2002:a17:906:7709:: with SMTP id q9mr23493088ejm.123.1595913302467; Mon, 27 Jul 2020 22:15:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595913302; cv=none; d=google.com; s=arc-20160816; b=iIFC06anEIT0loBylgjUPU6O0TqL6IMpafCRoibn+mytcdZDyxBPS3UGfk/DLuYj1X unAuJY3qj7HEuwBfRAUJjGIqBq4d7yoVqnlG3ZK7gUNLz0OlkMjAUP9hgJ3XFpoKlcnN z8044Ua084QBrjlzL8T3/ue0cw30GvIqEiNJ2OdIoJM68zSnKrCsVRFQaOP2/+8+G0eA q4VhTc5PSf3OZd0DYMBzXEQDNE0il6fP+dwh0lFK+Ie1zUs+xrWe0a53rq6y4NvmEb7I WNul2c/KOj1wTA+ukDC02b4qBSlsxAQu4Ndqp9mfbPWaji2WDaPozpCKtFf0Li3rWfZg SgfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cTsMNGVz/6FnfILPoy4BCnh+qoVojN51Hm/njwANGhM=; b=f+R5oDqotHhLIL1zpx4Epaozc3cbBSz1yGvH3bJe83J1zPJIEPn8wDXHQnMxymtJQe QKA3AqkBqaxPGdPvkWeL8q3JZytTwDLD6o40dJGo1xnv9uxh1OnezC+50pGqq67LkiYE KLFuL4bHPiJVk/QvPfjKQS45Tkn8xt8Q0plmbUKomoL0Ab/rSFi3ZN5iLcx2UPON0ou9 vn6xgxCYg7v8itE3ByBwnDXBFIZagFMo/t8IxTwXdF05+uS97qSm9T3wUiOwdBL+yMlC J5bH2CcoIFSb8G1pXcHVnGuiq+LUQznQuObTu0hENarvDiV27sz8CCOxVRQXydKnMGTp IOKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="D4u/UIbz"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c3si4103786edm.469.2020.07.27.22.14.40; Mon, 27 Jul 2020 22:15:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="D4u/UIbz"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726858AbgG1FMZ (ORCPT + 99 others); Tue, 28 Jul 2020 01:12:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:33874 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726251AbgG1FMY (ORCPT ); Tue, 28 Jul 2020 01:12:24 -0400 Received: from aquarius.haifa.ibm.com (nesher1.haifa.il.ibm.com [195.110.40.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5790E22B3F; Tue, 28 Jul 2020 05:12:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595913143; bh=4WuJOQlNfEjZEgWh7mIgx+GQ0z3C84AGorDeAuZhOK8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D4u/UIbzLlEIUGvsu7oIEk1r9y1HdyXe4bGFS4uPFFZlE1SvR0Ic/VsazPLkmlfYo MGSySQinsMEKx0a460QO0p336yu3q4NZYJLjS2vVr0K3k0pnoZ2v/GrKkVnCKHf3ZV mwea1G2DA7ZiDVovETmAVBrYbEJIl1dz6OHL4Gts= From: Mike Rapoport To: Andrew Morton Cc: Andy Lutomirski , Benjamin Herrenschmidt , Borislav Petkov , Catalin Marinas , Christoph Hellwig , Dave Hansen , Ingo Molnar , Marek Szyprowski , Max Filippov , Michael Ellerman , Michal Simek , Mike Rapoport , Mike Rapoport , Palmer Dabbelt , Paul Mackerras , Paul Walmsley , Peter Zijlstra , Russell King , Stafford Horne , Thomas Gleixner , Will Deacon , Yoshinori Sato , clang-built-linux@googlegroups.com, iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-c6x-dev@linux-c6x.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, linux-xtensa@linux-xtensa.org, linuxppc-dev@lists.ozlabs.org, openrisc@lists.librecores.org, sparclinux@vger.kernel.org, uclinux-h8-devel@lists.sourceforge.jp, x86@kernel.org Subject: [PATCH 01/15] KVM: PPC: Book3S HV: simplify kvm_cma_reserve() Date: Tue, 28 Jul 2020 08:11:39 +0300 Message-Id: <20200728051153.1590-2-rppt@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200728051153.1590-1-rppt@kernel.org> References: <20200728051153.1590-1-rppt@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mike Rapoport The memory size calculation in kvm_cma_reserve() traverses memblock.memory rather than simply call memblock_phys_mem_size(). The comment in that function suggests that at some point there should have been call to memblock_analyze() before memblock_phys_mem_size() could be used. As of now, there is no memblock_analyze() at all and memblock_phys_mem_size() can be used as soon as cold-plug memory is registerd with memblock. Replace loop over memblock.memory with a call to memblock_phys_mem_size(). Signed-off-by: Mike Rapoport --- arch/powerpc/kvm/book3s_hv_builtin.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv_builtin.c b/arch/powerpc/kvm/book3s_hv_builtin.c index 7cd3cf3d366b..56ab0d28de2a 100644 --- a/arch/powerpc/kvm/book3s_hv_builtin.c +++ b/arch/powerpc/kvm/book3s_hv_builtin.c @@ -95,22 +95,15 @@ EXPORT_SYMBOL_GPL(kvm_free_hpt_cma); void __init kvm_cma_reserve(void) { unsigned long align_size; - struct memblock_region *reg; - phys_addr_t selected_size = 0; + phys_addr_t selected_size; /* * We need CMA reservation only when we are in HV mode */ if (!cpu_has_feature(CPU_FTR_HVMODE)) return; - /* - * We cannot use memblock_phys_mem_size() here, because - * memblock_analyze() has not been called yet. - */ - for_each_memblock(memory, reg) - selected_size += memblock_region_memory_end_pfn(reg) - - memblock_region_memory_base_pfn(reg); + selected_size = PHYS_PFN(memblock_phys_mem_size()); selected_size = (selected_size * kvm_cma_resv_ratio / 100) << PAGE_SHIFT; if (selected_size) { pr_debug("%s: reserving %ld MiB for global area\n", __func__, -- 2.26.2