EPT 1GB page support
cover EPT 1GB page support
PATCH 1/3 KVM: x86: Rename gb_page_enable() to get_lpage_level() in kvm_x86_ops
Then the callback can provide the maximum supported large page level, which is more flexible.
Also move the gb page support into x86_64 specific.
--- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/svm.c | 6 +++--- arch/x86/kvm/vmx.c | 6 +++--- arch/x86/kvm/x86.c | 5 ++++- 4 files changed, 11 insertions(+), 8 deletions(-)
arch/x86/include/asm/kvm_host.h +1 -1
@@ -520,7 +520,7 @@ struct kvm_x86_ops {int (*set_tss_addr)(struct kvm *kvm,unsigned int addr);int (*get_tdp_level)(void );u64 (*get_mt_mask)(struct kvm_vcpu *vcpu,gfn_t gfn,bool is_mmio); -bool (*gb_page_enable)(void ); +int (*get_lpage_level)(void );bool (*rdtscp_supported)(void );const struct trace_print_flags *exit_reasons_str;
arch/x86/kvm/svm.c +3 -3
@@ -2911,9 +2911,9 @@ static const struct trace_print_flags svm_exit_reasons_str[] = { { -1, NULL } }; -static bool svm_gb_page_enable (void ) +static int svm_get_lpage_level (void ) { -return true; +return 3 ;/* PT_PDPE_LEVEL */ }static bool svm_rdtscp_supported (void )
@@ -2986,7 +2986,7 @@ static struct kvm_x86_ops svm_x86_ops = { .get_mt_mask = svm_get_mt_mask, .exit_reasons_str = svm_exit_reasons_str, - .gb_page_enable = svm_gb_page_enable, + .get_lpage_level = svm_get_lpage_level, .cpuid_update = svm_cpuid_update,
arch/x86/kvm/vmx.c +3 -3
@@ -4011,9 +4011,9 @@ static const struct trace_print_flags vmx_exit_reasons_str[] = { { -1, NULL } }; -static bool vmx_gb_page_enable (void ) +static int vmx_get_lpage_level (void ) { -return false; +return 2 ;/* PT_DIRECTORY_LEVEL */ }static inline u32 bit (int bitno)
@@ -4106,7 +4106,7 @@ static struct kvm_x86_ops vmx_x86_ops = { .get_mt_mask = vmx_get_mt_mask, .exit_reasons_str = vmx_exit_reasons_str, - .gb_page_enable = vmx_gb_page_enable, + .get_lpage_level = vmx_get_lpage_level, .cpuid_update = vmx_cpuid_update,
arch/x86/kvm/x86.c +4 -1
@@ -1641,10 +1641,13 @@ static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, u32 index, int *nent, int maxnent) { unsigned f_nx = is_efer_nx() ? F(NX) : 0; -unsigned f_gbpages = kvm_x86_ops->gb_page_enable () ?F (GBPAGES ) :0 ;#ifdef CONFIG_X86_64 +/* PT_PDPE_LEVEL (mapping 1GB page) is 3 */ +unsigned f_gbpages = (kvm_x86_ops->get_lpage_level () ==3 ) ? +F (GBPAGES ) :0 ;unsigned f_lm =F (LM );#else +unsigned f_gbpages =0 ;unsigned f_lm =0 ;#endif unsigned f_rdtscp = kvm_x86_ops->rdtscp_supported () ?F (RDTSCP ) :0 ;
Signature · 1 line
1.5.4.5
PATCH 2/3 KVM: x86: Fix host_mapping_level()
In reply to Sheng YangWhen found a error hva, should not return PAGE_SIZE but the level...
Also clean up the coding style of the following loop.
--- arch/x86/kvm/mmu.c | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-)
arch/x86/kvm/mmu.c +2 -4
@@ -477,7 +477,7 @@ static int host_mapping_level(struct kvm *kvm, gfn_t gfn) addr =gfn_to_hva (kvm, gfn);if (kvm_is_error_hva (addr)) -return page_size; +return PT_PAGE_TABLE_LEVEL ;down_read (¤t->mm->mmap_sem); vma =find_vma (current->mm, addr);
@@ -515,11 +515,9 @@ static int mapping_level(struct kvm_vcpu *vcpu, gfn_t large_gfn)if (host_level ==PT_PAGE_TABLE_LEVEL )return host_level; -for (level =PT_DIRECTORY_LEVEL ; level <= host_level; ++level) { - +for (level =PT_DIRECTORY_LEVEL ; level <= host_level; ++level)if (has_wrprotected_page (vcpu->kvm, large_gfn, level))break ; - }return level -1 ; }
Signature · 1 line
1.5.4.5
PATCH 3/3 KVM: VMX: Enable EPT 1GB page support
In reply to Sheng Yang--- arch/x86/include/asm/vmx.h | 1 + arch/x86/kvm/mmu.c | 8 +++++--- arch/x86/kvm/vmx.c | 11 ++++++++++- 3 files changed, 16 insertions(+), 4 deletions(-)
arch/x86/include/asm/vmx.h +1 -0
@@ -364,6 +364,7 @@ enum vmcs_field {#define VMX_EPTP_UC_BIT (1ull << 8)#define VMX_EPTP_WB_BIT (1ull << 14)#define VMX_EPT_2MB_PAGE_BIT (1ull << 16) +#define VMX_EPT_1GB_PAGE_BIT (1ull << 17)#define VMX_EPT_EXTENT_INDIVIDUAL_BIT (1ull << 24)#define VMX_EPT_EXTENT_CONTEXT_BIT (1ull << 25)#define VMX_EPT_EXTENT_GLOBAL_BIT (1ull << 26)
arch/x86/kvm/mmu.c +5 -3
@@ -503,8 +503,7 @@ out:static int mapping_level (struct kvm_vcpu *vcpu,gfn_t large_gfn) {struct kvm_memory_slot *slot; -int host_level; -int level =PT_PAGE_TABLE_LEVEL ; +int host_level, level, max_level; slot =gfn_to_memslot (vcpu->kvm, large_gfn);if (slot && slot->dirty_bitmap)
@@ -515,7 +514,10 @@ static int mapping_level(struct kvm_vcpu *vcpu, gfn_t large_gfn)if (host_level ==PT_PAGE_TABLE_LEVEL )return host_level; -for (level =PT_DIRECTORY_LEVEL ; level <= host_level; ++level) + max_level = kvm_x86_ops->get_lpage_level () < host_level ? + kvm_x86_ops->get_lpage_level () : host_level; + +for (level =PT_DIRECTORY_LEVEL ; level <= max_level; ++level)if (has_wrprotected_page (vcpu->kvm, large_gfn, level))break ;
arch/x86/kvm/vmx.c +10 -1
@@ -318,6 +318,11 @@ static inline bool cpu_has_vmx_ept_2m_page(void)return !!(vmx_capability.ept &VMX_EPT_2MB_PAGE_BIT ); } +static inline bool cpu_has_vmx_ept_1g_page (void ) +{ +return !!(vmx_capability.ept &VMX_EPT_1GB_PAGE_BIT ); +} +static inline int cpu_has_vmx_invept_individual_addr (void ) {return !!(vmx_capability.ept &VMX_EPT_EXTENT_INDIVIDUAL_BIT );
@@ -4013,7 +4018,11 @@ static const struct trace_print_flags vmx_exit_reasons_str[] = {static int vmx_get_lpage_level (void ) { -return 2 ;/* PT_DIRECTORY_LEVEL */ +if (enable_ept && !cpu_has_vmx_ept_1g_page ()) +return 2 ;/* PT_DIRECTORY_LEVEL */ +else +/* For shadow and EPT supported 1GB page */ +return 3 ;/* PT_PDPE_LEVEL */ }static inline u32 bit (int bitno)
Signature · 1 line
1.5.4.5
Re: [PATCH 3/3] KVM: VMX: Enable EPT 1GB page support
Quoted 12 lines · Sheng Yang
Signed-off-by Sheng Yang<[email protected]>--- arch/x86/include/asm/vmx.h | 1 + arch/x86/kvm/mmu.c | 8 +++++--- arch/x86/kvm/vmx.c | 11 ++++++++++- 3 files changed, 16 insertions(+), 4 deletions(-)arch/x86/include/asm/vmx.h +0
-0
arch/x86/include/asm/vmx.h enum vmcs_field { · line 368
Quoted 5 lines
arch/x86/include/asm/vmx.h +1
-0@@ -364,6 +364,7 @@ enum vmcs_field {#define VMX_EPTP_UC_BIT (1ull<< 8)#define VMX_EPTP_WB_BIT (1ull<< 14)#define VMX_EPT_2MB_PAGE_BIT (1ull<< 16) +#define VMX_EPT_1GB_PAGE_BIT (1ull<< 17)
Can you share when this feature will be available in hardware?
arch/x86/include/asm/vmx.h enum vmcs_field {
Quoted 11 lines
arch/x86/include/asm/vmx.h +5
-1static int vmx_get_lpage_level (void ) { -return 2 ;/* PT_DIRECTORY_LEVEL */ +if (enable_ept&& !cpu_has_vmx_ept_1g_page ()) +return 2 ;/* PT_DIRECTORY_LEVEL */ +else +/* For shadow and EPT supported 1GB page */ +return 3 ;/* PT_PDPE_LEVEL */ }
Why not use the defines instead of numbers? It will reduce change when we change PT_*_LEVEL to be zero based instead of one based.
Patchset looks good; second patch should go into .33 and stable, no?
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH 3/3] KVM: VMX: Enable EPT 1GB page support
Quoted 8 lines · On Tuesday 05 January 2010 18:43:21 Avi Kivity wrote:
Quoted 7 lines · Sheng Yang
Signed-off-by Sheng Yang<[email protected]>--- arch/x86/include/asm/vmx.h | 1 + arch/x86/kvm/mmu.c | 8 +++++--- arch/x86/kvm/vmx.c | 11 ++++++++++- 3 files changed, 16 insertions(+), 4 deletions(-)
Quoted 11 lines
arch/x86/include/asm/vmx.h enum vmcs_field { · line 367
Quoted 9 lines
arch/x86/include/asm/vmx.h +1
-0@@ -364,6 +364,7 @@ enum vmcs_field {#define VMX_EPTP_UC_BIT (1ull<< 8)#define VMX_EPTP_WB_BIT (1ull<< 14)#define VMX_EPT_2MB_PAGE_BIT (1ull<< 16) +#define VMX_EPT_1GB_PAGE_BIT (1ull<< 17)Can you share when this feature will be available in hardware?
I think it should be with the 32nm Core i7 (at least highend server edition), slated for early 2010 release.
Quoted 13 lines
arch/x86/include/asm/vmx.h enum vmcs_field {
Quoted 10 lines
arch/x86/include/asm/vmx.h +5
-1static int vmx_get_lpage_level (void ) { -return 2 ;/* PT_DIRECTORY_LEVEL */ +if (enable_ept&& !cpu_has_vmx_ept_1g_page ()) +return 2 ;/* PT_DIRECTORY_LEVEL */ +else +/* For shadow and EPT supported 1GB page */ +return 3 ;/* PT_PDPE_LEVEL */ }Why not use the defines instead of numbers? It will reduce change when we change PT_*_LEVEL to be zero based instead of one based.
Oh, sure (caused by a little chaos in mind...). Patch 1 is also affected(cpuid). Would resent the patchset soon.
Quoted 3 lines
Patchset looks good; second patch should go into .33 and stable, no?
Sure. I would cc stable later.
Signature · 2 lines
regards Yang, Sheng