diff mbox series

[7/7] KVM: arm64: Use less bits for hyp_page refcount

Message ID 20210527125134.2116404-8-qperret@google.com (mailing list archive)
State New, archived
Headers show
Series KVM: arm64: Reduce hyp_vmemmap overhead | expand

Commit Message

Quentin Perret May 27, 2021, 12:51 p.m. UTC
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>
---
 arch/arm64/kvm/hyp/include/nvhe/gfp.h    | 2 ++
 arch/arm64/kvm/hyp/include/nvhe/memory.h | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

Comments

Marc Zyngier June 1, 2021, 3:21 p.m. UTC | #1
On Thu, 27 May 2021 13:51:34 +0100,
Quentin Perret <qperret@google.com> wrote:
> 
> 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>
> ---
>  arch/arm64/kvm/hyp/include/nvhe/gfp.h    | 2 ++
>  arch/arm64/kvm/hyp/include/nvhe/memory.h | 2 +-
>  2 files changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/kvm/hyp/include/nvhe/gfp.h b/arch/arm64/kvm/hyp/include/nvhe/gfp.h
> index d420e5c0845f..a82f73faf41e 100644
> --- a/arch/arm64/kvm/hyp/include/nvhe/gfp.h
> +++ b/arch/arm64/kvm/hyp/include/nvhe/gfp.h
> @@ -24,6 +24,8 @@ struct hyp_pool {
>  
>  static inline void hyp_page_ref_inc(struct hyp_page *p)
>  {
> +	if (p->refcount == USHRT_MAX)
> +		BUG();

nit: BUG_ON(p->refcount == USHRT_MAX);

>  	p->refcount++;
>  }
>  
> diff --git a/arch/arm64/kvm/hyp/include/nvhe/memory.h b/arch/arm64/kvm/hyp/include/nvhe/memory.h
> index 3fe34fa30ea4..592b7edb3edb 100644
> --- a/arch/arm64/kvm/hyp/include/nvhe/memory.h
> +++ b/arch/arm64/kvm/hyp/include/nvhe/memory.h
> @@ -8,7 +8,7 @@
>  #include <linux/types.h>
>  
>  struct hyp_page {
> -	unsigned int refcount;
> +	unsigned short refcount;
>  	unsigned short order;
>  };
>  
> -- 
> 2.31.1.818.g46aad6cb9e-goog
> 
>
diff mbox series

Patch

diff --git a/arch/arm64/kvm/hyp/include/nvhe/gfp.h b/arch/arm64/kvm/hyp/include/nvhe/gfp.h
index d420e5c0845f..a82f73faf41e 100644
--- a/arch/arm64/kvm/hyp/include/nvhe/gfp.h
+++ b/arch/arm64/kvm/hyp/include/nvhe/gfp.h
@@ -24,6 +24,8 @@  struct hyp_pool {
 
 static inline void hyp_page_ref_inc(struct hyp_page *p)
 {
+	if (p->refcount == USHRT_MAX)
+		BUG();
 	p->refcount++;
 }
 
diff --git a/arch/arm64/kvm/hyp/include/nvhe/memory.h b/arch/arm64/kvm/hyp/include/nvhe/memory.h
index 3fe34fa30ea4..592b7edb3edb 100644
--- a/arch/arm64/kvm/hyp/include/nvhe/memory.h
+++ b/arch/arm64/kvm/hyp/include/nvhe/memory.h
@@ -8,7 +8,7 @@ 
 #include <linux/types.h>
 
 struct hyp_page {
-	unsigned int refcount;
+	unsigned short refcount;
 	unsigned short order;
 };