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 X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6E8DC433DF for ; Tue, 4 Aug 2020 13:55:32 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (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 1D79E2086A for ; Tue, 4 Aug 2020 13:55:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=axtens.net header.i=@axtens.net header.b="jumdjySC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1D79E2086A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=axtens.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4BLbqj1WHczDqPb for ; Tue, 4 Aug 2020 23:55:29 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=axtens.net (client-ip=2607:f8b0:4864:20::441; helo=mail-pf1-x441.google.com; envelope-from=dja@axtens.net; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=axtens.net Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=axtens.net header.i=@axtens.net header.a=rsa-sha256 header.s=google header.b=jumdjySC; dkim-atps=neutral Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4BLbnJ3Rk4zDqLf for ; Tue, 4 Aug 2020 23:53:22 +1000 (AEST) Received: by mail-pf1-x441.google.com with SMTP id m8so13423460pfh.3 for ; Tue, 04 Aug 2020 06:53:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=nig2/fJdYyt3b0Q5A/SU+0msFseeyybXCaAI4dDRdTg=; b=jumdjySCSXZVJzizm9OUzoU9OXCS+Cfq57D4M9+nOmcjFx/ImlUYxx8bn1JnW+143W B6tMiLN9WKIVbxAyKxyw81HdIULr1/GZN+VKaYR0TvHVg/4jcAFDj42GWXCA2Swm1Yfw 5v27iYJTlRgBYWmLp+/HqtnWpSjejedeiZ1fo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=nig2/fJdYyt3b0Q5A/SU+0msFseeyybXCaAI4dDRdTg=; b=RpYzi6lWKaITJB/utUvIomRG4CQbWYbYHCs4KpOa5H740g/na0/WU7wXCdbFWJrf8N CPteppvxERhDvtRrGgGM2X3iW/m6x0NaGKZuYYTmPbOTm0ExnRk7Er39DLmfmt7yhgE1 VdpX8kMpbBshly1KRHRG5Rp40G1te2bUVgL+tNlx3vV9pK9a6EcJKJ+UkIrobNY1Bfmi 2gY+D/e/FHXav1x9UL9bZWLu17Ja1W/ttV8oBZOGwpehNvKl+Vkg2wtqa38SWzQZ/rie 4eRkQAaS2stGoAHoVsQGirYSsQA8bErkxNKkybtqL0oszeFren0gvTtNCfTlKRqI2mnd FLPg== X-Gm-Message-State: AOAM531P47UqywKQ8m/kqw63NI5nFfZJQ6JZatv6G9JOOP4sEFxMNVvK MtqhAK/9dRz19LLPeRch6yMvsg== X-Google-Smtp-Source: ABdhPJzULAmNSkaX32weXl1O34te5NSuX9EJVhPlxbPjsXptEZqiJedi5i9MSO/avpj2cLsHaUiFtw== X-Received: by 2002:a63:3587:: with SMTP id c129mr20025647pga.322.1596549199803; Tue, 04 Aug 2020 06:53:19 -0700 (PDT) Received: from localhost (2001-44b8-1113-6700-0414-2e33-60ed-75ec.static.ipv6.internode.on.net. [2001:44b8:1113:6700:414:2e33:60ed:75ec]) by smtp.gmail.com with ESMTPSA id g8sm9981404pfo.132.2020.08.04.06.53.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Aug 2020 06:53:19 -0700 (PDT) From: Daniel Axtens To: Mike Rapoport , Andrew Morton Subject: Re: [PATCH v2 01/17] KVM: PPC: Book3S HV: simplify kvm_cma_reserve() In-Reply-To: <20200802163601.8189-2-rppt@kernel.org> References: <20200802163601.8189-1-rppt@kernel.org> <20200802163601.8189-2-rppt@kernel.org> Date: Tue, 04 Aug 2020 23:53:15 +1000 Message-ID: <87tuxio6us.fsf@dja-thinkpad.axtens.net> MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Gleixner , Emil Renner Berthing , linux-sh@vger.kernel.org, Peter Zijlstra , Dave Hansen , linux-mips@vger.kernel.org, Max Filippov , Paul Mackerras , sparclinux@vger.kernel.org, linux-riscv@lists.infradead.org, Will Deacon , Christoph Hellwig , Marek Szyprowski , linux-arch@vger.kernel.org, linux-s390@vger.kernel.org, linux-c6x-dev@linux-c6x.org, Baoquan He , x86@kernel.org, Russell King , Mike Rapoport , clang-built-linux@googlegroups.com, Ingo Molnar , linux-arm-kernel@lists.infradead.org, Catalin Marinas , uclinux-h8-devel@lists.sourceforge.jp, linux-xtensa@linux-xtensa.org, openrisc@lists.librecores.org, Borislav Petkov , Andy Lutomirski , Paul Walmsley , Stafford Horne , Hari Bathini , Michal Simek , Yoshinori Sato , linux-mm@kvack.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, Palmer Dabbelt , linuxppc-dev@lists.ozlabs.org, Mike Rapoport Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" Hi Mike, > > 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; I think this is correct, but PHYS_PFN does x >> PAGE_SHIFT and then the next line does x << PAGE_SHIFT, so I think we could combine those two lines as: selected_size = PAGE_ALIGN(memblock_phys_mem_size() * kvm_cma_resv_ratio / 100); (I think that might technically change it from aligning down to aligning up but I don't think 1 page matters here.) Kind regards, Daniel > if (selected_size) { > pr_debug("%s: reserving %ld MiB for global area\n", __func__, > -- > 2.26.2