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=-5.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no 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 5A74CC433E0 for ; Fri, 5 Feb 2021 17:57:18 +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 DDF5264E0A for ; Fri, 5 Feb 2021 17:57:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DDF5264E0A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.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:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+MVUhpYYZVOUs5LGlDzz1pazWBrl29z9uqxlR8hizDI=; b=Zz1Mj3V0lyReXVi2zHwN49yqD k86+yPWiUbrZarYDUNK7malwGEl1wFmoPlEvT/OS/6MPC0KgXoWA+KCZYR8SwfNKcAXRbzyzW8Qoj U26HgS24iwfwBq1LAJjSXsF+1PHSyqIwvkO5Dc+CScKXOPu7WFYYjDW60ZCi+y29nFo4y8LAbbEjo 1azEfYbyyzdsC/wpVqBvAW3dyBFcwcKd86KYU3xlwYD+xCz9eG7GZSU0fEDssnhEOG987WnRvGiH3 S8n3S7KiN5DsCGYraA9a+l9q9Lq/cW+ykG30/2yyuwC1zpYzoMcADSb4iF4J0j+b102HXHp+E/wlT ygyFF3PaQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l85L3-000111-RK; Fri, 05 Feb 2021 17:56:13 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l85L0-0000zD-51 for linux-arm-kernel@lists.infradead.org; Fri, 05 Feb 2021 17:56:10 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4FCEA64DE8; Fri, 5 Feb 2021 17:56:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612547769; bh=tIx6Mq/q5bP075IBZ2ir3cjgV11ktDBdIgJkvpvVC3M=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=jTlgNtQ+Yw6PFVByGmHUzsyUYEpwKsJzsW+GNjtotiY8po0ywRgaiSjr1GuAsoMeR x+IR75GE7rrnakWiqzHBh0pNtil4DAStD/4cngKoM8MO8fypTdchG7tV9bDrEbIa7w f+b2Dm1Os9T7y+9ksGSx1SvohGbjRLeJxGbwH/96VBf/O8XGlMhJBW1NOYn1/w3SKb K83RbvvvM+XTwui5PkYnwUF+bft7iDfOSasn/J2V40uzD7vOP11AIQO3w8HrcHl7Yl QibMDqZEl9DdxiYCusF7CLgyazJvBPi+SAVwgsOQPH9kauUz65mCbKNapKpxju4iyo JNCM2nQUL+HXw== Date: Fri, 5 Feb 2021 17:56:02 +0000 From: Will Deacon To: Quentin Perret Subject: Re: [RFC PATCH v2 16/26] KVM: arm64: Prepare Hyp memory protection Message-ID: <20210205175602.GG22665@willie-the-truck> References: <20210108121524.656872-1-qperret@google.com> <20210108121524.656872-17-qperret@google.com> <20210203143709.GA18907@willie-the-truck> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210205_125610_276741_B4164F94 X-CRM114-Status: GOOD ( 24.42 ) 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 , devicetree@vger.kernel.org, kernel-team@android.com, Suzuki K Poulose , android-kvm@google.com, Catalin Marinas , Fuad Tabba , linux-kernel@vger.kernel.org, Rob Herring , James Morse , linux-arm-kernel@lists.infradead.org, Marc Zyngier , David Brazdil , Frank Rowand , kvmarm@lists.cs.columbia.edu, Julien Thierry Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Feb 04, 2021 at 10:47:08AM +0000, Quentin Perret wrote: > On Wednesday 03 Feb 2021 at 14:37:10 (+0000), Will Deacon wrote: > > On Fri, Jan 08, 2021 at 12:15:14PM +0000, Quentin Perret wrote: > > > +static inline unsigned long __hyp_pgtable_max_pages(unsigned long nr_pages) > > > +{ > > > + unsigned long total = 0, i; > > > + > > > + /* Provision the worst case scenario with 4 levels of page-table */ > > > + for (i = 0; i < 4; i++) { > > > > Looks like you want KVM_PGTABLE_MAX_LEVELS, so maybe move that into a > > header? > > Will do. > > > > > > + nr_pages = DIV_ROUND_UP(nr_pages, PTRS_PER_PTE); > > > + total += nr_pages; > > > + } > > > > ... that said, I'm not sure this needs to iterate at all. What exactly are > > you trying to compute? > > I'm trying to figure out how many pages I will need to construct a > page-table covering nr_pages contiguous pages. The first iteration tells > me how many level 0 pages I need to cover nr_pages, the second iteration > how many level 1 pages I need to cover the level 0 pages, and so on... Ah, you iterate from leaves back to the root. Got it, thanks. > I might be doing this naively though. Got a better idea? I thought I did, but I ended up with something based on a geometric series and it looks terrible to code-up in C without, err, iterating like you do. So yeah, ignore me :) > > > + > > > + return total; > > > +} > > > + > > > +static inline unsigned long hyp_s1_pgtable_size(void) > > > +{ > > > + struct hyp_memblock_region *reg; > > > + unsigned long nr_pages, res = 0; > > > + int i; > > > + > > > + if (kvm_nvhe_sym(hyp_memblock_nr) <= 0) > > > + return 0; > > > > It's a bit grotty having this be signed. Why do we need to encode the error > > case differently from the 0 case? > > Here specifically we don't, but it is needed in early_init_dt_add_memory_hyp() > to distinguish the overflow case from the first memblock being added. Fair enough, but if you figure out a way for hyp_memblock_nr to be unsigned, I think that would be preferable. Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel