Re: [RFC PATCH v2 16/26] KVM: arm64: Prepare Hyp memory protection
From: Will Deacon <will@kernel.org>
Date: 2021-02-05 18:00:28
Also in:
kvmarm, linux-devicetree, lkml
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:quoted
On Fri, Jan 08, 2021 at 12:15:14PM +0000, Quentin Perret wrote:quoted
+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.quoted
quoted
+ 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 :)
quoted
quoted
+ + 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