* [PATCH 0/4 v2] EPT 1GB page support
@ 2010-01-05 11:02 Sheng Yang
2010-01-05 11:02 ` [PATCH 1/4] KVM: x86: Moving PT_*_LEVEL to mmu.h Sheng Yang
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Sheng Yang @ 2010-01-05 11:02 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti; +Cc: kvm
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/4] KVM: x86: Moving PT_*_LEVEL to mmu.h
2010-01-05 11:02 [PATCH 0/4 v2] EPT 1GB page support Sheng Yang
@ 2010-01-05 11:02 ` Sheng Yang
2010-01-05 11:02 ` [PATCH 2/4] KVM: x86: Rename gb_page_enable() to get_lpage_level() in kvm_x86_ops Sheng Yang
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: Sheng Yang @ 2010-01-05 11:02 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti; +Cc: kvm, Sheng Yang
We can use them in x86.c and vmx.c now...
Signed-off-by: Sheng Yang <sheng@linux.intel.com>
---
arch/x86/kvm/mmu.c | 4 ----
arch/x86/kvm/mmu.h | 4 ++++
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index c43c2ab..15daf3c 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -142,10 +142,6 @@ module_param(oos_shadow, bool, 0644);
#define PFERR_RSVD_MASK (1U << 3)
#define PFERR_FETCH_MASK (1U << 4)
-#define PT_PDPE_LEVEL 3
-#define PT_DIRECTORY_LEVEL 2
-#define PT_PAGE_TABLE_LEVEL 1
-
#define RMAP_EXT 4
#define ACC_EXEC_MASK 1
diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
index 4567d80..ff58342 100644
--- a/arch/x86/kvm/mmu.h
+++ b/arch/x86/kvm/mmu.h
@@ -38,6 +38,10 @@
#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
+
int kvm_mmu_get_spte_hierarchy(struct kvm_vcpu *vcpu, u64 addr, u64 sptes[4]);
static inline void kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu)
--
1.5.4.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/4] KVM: x86: Rename gb_page_enable() to get_lpage_level() in kvm_x86_ops
2010-01-05 11:02 [PATCH 0/4 v2] EPT 1GB page support Sheng Yang
2010-01-05 11:02 ` [PATCH 1/4] KVM: x86: Moving PT_*_LEVEL to mmu.h Sheng Yang
@ 2010-01-05 11:02 ` Sheng Yang
2010-01-05 11:02 ` [PATCH 3/4] KVM: x86: Fix host_mapping_level() Sheng Yang
2010-01-05 11:02 ` [PATCH 4/4] KVM: VMX: Enable EPT 1GB page support Sheng Yang
3 siblings, 0 replies; 8+ messages in thread
From: Sheng Yang @ 2010-01-05 11:02 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti; +Cc: kvm, Sheng Yang
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.
Signed-off-by: Sheng Yang <sheng@linux.intel.com>
---
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 | 4 +++-
4 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index fe4df46..31b986f 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -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;
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index b373ae6..cf64fc0 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -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 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,
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 2cc9b7e..4177473 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -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 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,
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index fd6e1a5..bc8881a 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1641,10 +1641,12 @@ 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
+ unsigned f_gbpages = (kvm_x86_ops->get_lpage_level() == PT_PDPE_LEVEL)
+ ? 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;
--
1.5.4.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/4] KVM: x86: Fix host_mapping_level()
2010-01-05 11:02 [PATCH 0/4 v2] EPT 1GB page support Sheng Yang
2010-01-05 11:02 ` [PATCH 1/4] KVM: x86: Moving PT_*_LEVEL to mmu.h Sheng Yang
2010-01-05 11:02 ` [PATCH 2/4] KVM: x86: Rename gb_page_enable() to get_lpage_level() in kvm_x86_ops Sheng Yang
@ 2010-01-05 11:02 ` Sheng Yang
2010-01-05 11:02 ` [PATCH 4/4] KVM: VMX: Enable EPT 1GB page support Sheng Yang
3 siblings, 0 replies; 8+ messages in thread
From: Sheng Yang @ 2010-01-05 11:02 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti; +Cc: kvm, Sheng Yang, stable
When found a error hva, should not return PAGE_SIZE but the level...
Also clean up the coding style of the following loop.
Cc: stable@kernel.org
Signed-off-by: Sheng Yang <sheng@linux.intel.com>
---
arch/x86/kvm/mmu.c | 6 ++----
1 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 15daf3c..43cf2ea 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -473,7 +473,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);
@@ -511,11 +511,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;
}
--
1.5.4.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 4/4] KVM: VMX: Enable EPT 1GB page support
2010-01-05 11:02 [PATCH 0/4 v2] EPT 1GB page support Sheng Yang
` (2 preceding siblings ...)
2010-01-05 11:02 ` [PATCH 3/4] KVM: x86: Fix host_mapping_level() Sheng Yang
@ 2010-01-05 11:02 ` Sheng Yang
2010-01-06 9:19 ` Marcelo Tosatti
3 siblings, 1 reply; 8+ messages in thread
From: Sheng Yang @ 2010-01-05 11:02 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti; +Cc: kvm, Sheng Yang
Signed-off-by: Sheng Yang <sheng@linux.intel.com>
---
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(-)
diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h
index 713ed9a..43f1e9b 100644
--- a/arch/x86/include/asm/vmx.h
+++ b/arch/x86/include/asm/vmx.h
@@ -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)
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 43cf2ea..9012541 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -499,8 +499,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)
@@ -511,7 +510,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;
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 4177473..12b5661 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -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 PT_DIRECTORY_LEVEL;
+ if (enable_ept && !cpu_has_vmx_ept_1g_page())
+ return PT_DIRECTORY_LEVEL;
+ else
+ /* For shadow and EPT supported 1GB page */
+ return PT_PDPE_LEVEL;
}
static inline u32 bit(int bitno)
--
1.5.4.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 4/4] KVM: VMX: Enable EPT 1GB page support
2010-01-05 11:02 ` [PATCH 4/4] KVM: VMX: Enable EPT 1GB page support Sheng Yang
@ 2010-01-06 9:19 ` Marcelo Tosatti
2010-01-06 9:25 ` Sheng Yang
0 siblings, 1 reply; 8+ messages in thread
From: Marcelo Tosatti @ 2010-01-06 9:19 UTC (permalink / raw)
To: Sheng Yang; +Cc: Avi Kivity, kvm
On Tue, Jan 05, 2010 at 07:02:29PM +0800, Sheng Yang wrote:
>
> Signed-off-by: Sheng Yang <sheng@linux.intel.com>
> ---
> 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(-)
>
> diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h
> index 713ed9a..43f1e9b 100644
> --- a/arch/x86/include/asm/vmx.h
> +++ b/arch/x86/include/asm/vmx.h
> @@ -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)
> diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
> index 43cf2ea..9012541 100644
> --- a/arch/x86/kvm/mmu.c
> +++ b/arch/x86/kvm/mmu.c
> @@ -499,8 +499,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)
> @@ -511,7 +510,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;
> +
BUG_ON(kvm_x86_ops->get_lpage_level() < host_level) instead? See
the if (host_level == PT_PAGE_TABLE_LEVEL) above.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 4/4] KVM: VMX: Enable EPT 1GB page support
2010-01-06 9:19 ` Marcelo Tosatti
@ 2010-01-06 9:25 ` Sheng Yang
2010-01-06 10:02 ` Marcelo Tosatti
0 siblings, 1 reply; 8+ messages in thread
From: Sheng Yang @ 2010-01-06 9:25 UTC (permalink / raw)
To: Marcelo Tosatti; +Cc: Avi Kivity, kvm
On Wednesday 06 January 2010 17:19:15 Marcelo Tosatti wrote:
> On Tue, Jan 05, 2010 at 07:02:29PM +0800, Sheng Yang wrote:
> > Signed-off-by: Sheng Yang <sheng@linux.intel.com>
> > ---
> > 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(-)
> >
> > diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h
> > index 713ed9a..43f1e9b 100644
> > --- a/arch/x86/include/asm/vmx.h
> > +++ b/arch/x86/include/asm/vmx.h
> > @@ -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)
> > diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
> > index 43cf2ea..9012541 100644
> > --- a/arch/x86/kvm/mmu.c
> > +++ b/arch/x86/kvm/mmu.c
> > @@ -499,8 +499,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)
> > @@ -511,7 +510,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;
> > +
>
> BUG_ON(kvm_x86_ops->get_lpage_level() < host_level) instead? See
> the if (host_level == PT_PAGE_TABLE_LEVEL) above.
Sorry, I don't understand...
Here, EPT can support either 2MB or 1GB page at most, So we represent the
value through get_lpage_level(). Now 1GB page backed host memory can still
using by 2MB page backed EPT if 1GB page EPT is not supported in the
processor.
--
regards
Yang, Sheng
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 4/4] KVM: VMX: Enable EPT 1GB page support
2010-01-06 9:25 ` Sheng Yang
@ 2010-01-06 10:02 ` Marcelo Tosatti
0 siblings, 0 replies; 8+ messages in thread
From: Marcelo Tosatti @ 2010-01-06 10:02 UTC (permalink / raw)
To: Sheng Yang; +Cc: Avi Kivity, kvm
On Wed, Jan 06, 2010 at 05:25:27PM +0800, Sheng Yang wrote:
> > > - 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;
> > > +
> >
> > BUG_ON(kvm_x86_ops->get_lpage_level() < host_level) instead? See
> > the if (host_level == PT_PAGE_TABLE_LEVEL) above.
>
> Sorry, I don't understand...
>
> Here, EPT can support either 2MB or 1GB page at most, So we represent the
> value through get_lpage_level(). Now 1GB page backed host memory can still
> using by 2MB page backed EPT if 1GB page EPT is not supported in the
> processor.
Oh, OK, i misundertood.
Applied, thanks.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2010-01-06 10:03 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-05 11:02 [PATCH 0/4 v2] EPT 1GB page support Sheng Yang
2010-01-05 11:02 ` [PATCH 1/4] KVM: x86: Moving PT_*_LEVEL to mmu.h Sheng Yang
2010-01-05 11:02 ` [PATCH 2/4] KVM: x86: Rename gb_page_enable() to get_lpage_level() in kvm_x86_ops Sheng Yang
2010-01-05 11:02 ` [PATCH 3/4] KVM: x86: Fix host_mapping_level() Sheng Yang
2010-01-05 11:02 ` [PATCH 4/4] KVM: VMX: Enable EPT 1GB page support Sheng Yang
2010-01-06 9:19 ` Marcelo Tosatti
2010-01-06 9:25 ` Sheng Yang
2010-01-06 10:02 ` Marcelo Tosatti
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.