diff mbox series

KVM: x86: move definition PT_MAX_HUGEPAGE_LEVEL and KVM_NR_PAGE_SIZES together

Message ID 20180928140850.42684-1-richard.weiyang@gmail.com (mailing list archive)
State New, archived
Headers show
Series KVM: x86: move definition PT_MAX_HUGEPAGE_LEVEL and KVM_NR_PAGE_SIZES together | expand

Commit Message

Wei Yang Sept. 28, 2018, 2:08 p.m. UTC
Currently, there are two definitions related to huge page, but a little bit
far from each other and seems loosely connected:

 * KVM_NR_PAGE_SIZES defines the number of different size a page could map
 * PT_MAX_HUGEPAGE_LEVEL means the maximum level of huge page

The number of different size a page could map equals the maximum level
of huge page, which is implied by current definition.

While current implementation may not be kind to readers and further
developers:

 * KVM_NR_PAGE_SIZES looks like a stand alone definition at first sight
 * in case we need to support more level, two places need to change

This patch tries to make these two definition more close, so that reader
and developer would feel more comfortable to manipulate.

Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
---
 arch/x86/include/asm/kvm_host.h | 10 +++++++++-
 arch/x86/kvm/mmu.h              |  5 -----
 2 files changed, 9 insertions(+), 6 deletions(-)

Comments

Paolo Bonzini Oct. 1, 2018, 2:01 p.m. UTC | #1
On 28/09/2018 16:08, Wei Yang wrote:
> Currently, there are two definitions related to huge page, but a little bit
> far from each other and seems loosely connected:
> 
>  * KVM_NR_PAGE_SIZES defines the number of different size a page could map
>  * PT_MAX_HUGEPAGE_LEVEL means the maximum level of huge page
> 
> The number of different size a page could map equals the maximum level
> of huge page, which is implied by current definition.
> 
> While current implementation may not be kind to readers and further
> developers:
> 
>  * KVM_NR_PAGE_SIZES looks like a stand alone definition at first sight
>  * in case we need to support more level, two places need to change
> 
> This patch tries to make these two definition more close, so that reader
> and developer would feel more comfortable to manipulate.
> 
> Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
> ---
>  arch/x86/include/asm/kvm_host.h | 10 +++++++++-
>  arch/x86/kvm/mmu.h              |  5 -----
>  2 files changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index 036dede47274..7422842caa9d 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -102,7 +102,15 @@
>  #define UNMAPPED_GVA (~(gpa_t)0)
>  
>  /* KVM Hugepage definitions for x86 */
> -#define KVM_NR_PAGE_SIZES	3
> +enum {
> +	PT_PAGE_TABLE_LEVEL   = 1,
> +	PT_DIRECTORY_LEVEL    = 2,
> +	PT_PDPE_LEVEL         = 3,
> +	/* set max level to the biggest one */
> +	PT_MAX_HUGEPAGE_LEVEL = PT_PDPE_LEVEL,
> +};
> +#define KVM_NR_PAGE_SIZES	(PT_MAX_HUGEPAGE_LEVEL - \
> +				 PT_PAGE_TABLE_LEVEL + 1)
>  #define KVM_HPAGE_GFN_SHIFT(x)	(((x) - 1) * 9)
>  #define KVM_HPAGE_GFN_SIZE(x)	(1UL << KVM_HPAGE_GFN_SHIFT(x))
>  #define KVM_HPAGE_GFN_MASK(x)	(~(KVM_HPAGE_GFN_SIZE(x) - 1))
> diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
> index 1fab69c0b2f3..99d549905311 100644
> --- a/arch/x86/kvm/mmu.h
> +++ b/arch/x86/kvm/mmu.h
> @@ -43,11 +43,6 @@
>  #define PT32_ROOT_LEVEL 2
>  #define PT32E_ROOT_LEVEL 3
>  
> -#define PT_PDPE_LEVEL 3
> -#define PT_DIRECTORY_LEVEL 2
> -#define PT_PAGE_TABLE_LEVEL 1
> -#define PT_MAX_HUGEPAGE_LEVEL (PT_PAGE_TABLE_LEVEL + KVM_NR_PAGE_SIZES - 1)
> -
>  static inline u64 rsvd_bits(int s, int e)
>  {
>  	if (e < s)
> 

Queued, thanks.

Paolo
diff mbox series

Patch

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 036dede47274..7422842caa9d 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -102,7 +102,15 @@ 
 #define UNMAPPED_GVA (~(gpa_t)0)
 
 /* KVM Hugepage definitions for x86 */
-#define KVM_NR_PAGE_SIZES	3
+enum {
+	PT_PAGE_TABLE_LEVEL   = 1,
+	PT_DIRECTORY_LEVEL    = 2,
+	PT_PDPE_LEVEL         = 3,
+	/* set max level to the biggest one */
+	PT_MAX_HUGEPAGE_LEVEL = PT_PDPE_LEVEL,
+};
+#define KVM_NR_PAGE_SIZES	(PT_MAX_HUGEPAGE_LEVEL - \
+				 PT_PAGE_TABLE_LEVEL + 1)
 #define KVM_HPAGE_GFN_SHIFT(x)	(((x) - 1) * 9)
 #define KVM_HPAGE_GFN_SIZE(x)	(1UL << KVM_HPAGE_GFN_SHIFT(x))
 #define KVM_HPAGE_GFN_MASK(x)	(~(KVM_HPAGE_GFN_SIZE(x) - 1))
diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
index 1fab69c0b2f3..99d549905311 100644
--- a/arch/x86/kvm/mmu.h
+++ b/arch/x86/kvm/mmu.h
@@ -43,11 +43,6 @@ 
 #define PT32_ROOT_LEVEL 2
 #define PT32E_ROOT_LEVEL 3
 
-#define PT_PDPE_LEVEL 3
-#define PT_DIRECTORY_LEVEL 2
-#define PT_PAGE_TABLE_LEVEL 1
-#define PT_MAX_HUGEPAGE_LEVEL (PT_PAGE_TABLE_LEVEL + KVM_NR_PAGE_SIZES - 1)
-
 static inline u64 rsvd_bits(int s, int e)
 {
 	if (e < s)