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,URIBL_BLOCKED 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 16382C433DF for ; Tue, 4 Aug 2020 14:33:15 +0000 (UTC) Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (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 CEA572177B for ; Tue, 4 Aug 2020 14:33:14 +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 CEA572177B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=axtens.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=iommu-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id A1E11861B2; Tue, 4 Aug 2020 14:33:14 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wgo0Hu7p3E7J; Tue, 4 Aug 2020 14:33:13 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id E7A198622A; Tue, 4 Aug 2020 14:33:13 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id E03A1C0051; Tue, 4 Aug 2020 14:33:13 +0000 (UTC) Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 22BA9C004C for ; Tue, 4 Aug 2020 14:25:23 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 1ABDB2052C for ; Tue, 4 Aug 2020 14:25:23 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id t2ObWsXrpLmE for ; Tue, 4 Aug 2020 14:25:22 +0000 (UTC) X-Greylist: delayed 00:24:13 by SQLgrey-1.7.6 Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by silver.osuosl.org (Postfix) with ESMTPS id 736C12012D for ; Tue, 4 Aug 2020 14:25:22 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id h12so10858622pgf.7 for ; Tue, 04 Aug 2020 07:25: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=HXE5M/Me3Smve0BSshFXZkryt4/pzsUzw3WVRanyoqKFDYWI6HzqKIDcaCEGjqXImW 34h62aRVVI2lfV/5k8lfH9M3aIVVU5JyU6aOPHbtcCEMWX4m1Zme9Dtq83opD1ulj6GN wLtcWmZe5qz78vprPJB7e2/u35emTtihuOLzoryFpH376rA1j32BxIE7lY+GfhXaednV YZfacsKcZoMARqvrAxjoM2R1wHQY1fVC9PUCUDnpkIt4qWVSGnwGxkmWpDwLeuJgR66q 6uLmOBkoLMH+1ddZrpBayfBifQFxDybEAmaj94q6t/6TwSCiWIVmshhVr7EUNmi+XFGS dwYg== X-Gm-Message-State: AOAM533VxvVlo6MG5glRq0BMntt4/2D0b6BXFmQaKMm+FKuUvvlShie2 PkadJTuvcl7FXsqlmxqmB/3yfIhlkQM= 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 X-Mailman-Approved-At: Tue, 04 Aug 2020 14:33:12 +0000 Cc: Thomas Gleixner , Emil Renner Berthing , linux-sh@vger.kernel.org, Peter Zijlstra , Benjamin Herrenschmidt , Dave Hansen , linux-mips@vger.kernel.org, Max Filippov , Paul Mackerras , sparclinux@vger.kernel.org, linux-riscv@lists.infradead.org, Will Deacon , Christoph Hellwig , linux-arch@vger.kernel.org, linux-s390@vger.kernel.org, linux-c6x-dev@linux-c6x.org, Michael Ellerman , 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 X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" 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 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu