]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: arm64: Use less bits for hyp_page refcount
authorQuentin Perret <qperret@google.com>
Tue, 8 Jun 2021 11:45:18 +0000 (11:45 +0000)
committerMarc Zyngier <maz@kernel.org>
Fri, 11 Jun 2021 12:24:12 +0000 (13:24 +0100)
The hyp_page refcount is currently encoded on 4 bytes even though we
never need to count that many objects in a page. Make it 2 bytes to save
some space in the vmemmap.

As overflows are more likely to happen as well, make sure to catch those
with a BUG in the increment function.

Signed-off-by: Quentin Perret <qperret@google.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20210608114518.748712-8-qperret@google.com
arch/arm64/kvm/hyp/include/nvhe/memory.h
arch/arm64/kvm/hyp/nvhe/page_alloc.c

index 3fe34fa30ea47acae53df57d7d3d1f35717bc676..592b7edb3edb4cdcb3a43855b3edf3a53c37e346 100644 (file)
@@ -8,7 +8,7 @@
 #include <linux/types.h>
 
 struct hyp_page {
-       unsigned int refcount;
+       unsigned short refcount;
        unsigned short order;
 };
 
index be07055bbc10f1507ebd54d2ee7ac3701594abe0..41fc25bdfb34660f470ef9dda78fe0a8a7aee989 100644 (file)
@@ -146,6 +146,7 @@ static struct hyp_page *__hyp_extract_page(struct hyp_pool *pool,
 
 static inline void hyp_page_ref_inc(struct hyp_page *p)
 {
+       BUG_ON(p->refcount == USHRT_MAX);
        p->refcount++;
 }