Skip to content

Commit 6929586

Browse files
Quentin PerretMarc Zyngier
authored andcommitted
KVM: arm64: Use less bits for hyp_page refcount
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
1 parent 87ec060 commit 6929586

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

arch/arm64/kvm/hyp/include/nvhe/memory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <linux/types.h>
99

1010
struct hyp_page {
11-
unsigned int refcount;
11+
unsigned short refcount;
1212
unsigned short order;
1313
};
1414

arch/arm64/kvm/hyp/nvhe/page_alloc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ static struct hyp_page *__hyp_extract_page(struct hyp_pool *pool,
146146

147147
static inline void hyp_page_ref_inc(struct hyp_page *p)
148148
{
149+
BUG_ON(p->refcount == USHRT_MAX);
149150
p->refcount++;
150151
}
151152

0 commit comments

Comments
 (0)