[kvm-devel] [PATCH 4/8] X86: export information about NPT to generic x86 code

2008-01-25 Thread Joerg Roedel
The generic x86 code has to know if the specific implementation uses Nested
Paging. In the generic code Nested Paging is called Hardware Assisted Paging
(HAP) to avoid confusion with (future) HAP implementations of other vendors.
This patch exports the availability of HAP to the generic x86 code.

Signed-off-by: Joerg Roedel <[EMAIL PROTECTED]>
---
 arch/x86/kvm/svm.c |7 +++
 arch/x86/kvm/vmx.c |7 +++
 include/asm-x86/kvm_host.h |2 ++
 3 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 2e718ff..d0bfdd8 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -1678,6 +1678,11 @@ static bool svm_cpu_has_accelerated_tpr(void)
return false;
 }
 
+static bool svm_hap_enabled(void)
+{
+   return npt_enabled;
+}
+
 static struct kvm_x86_ops svm_x86_ops = {
.cpu_has_kvm_support = has_svm,
.disabled_by_bios = is_disabled,
@@ -1734,6 +1739,8 @@ static struct kvm_x86_ops svm_x86_ops = {
.inject_pending_vectors = do_interrupt_requests,
 
.set_tss_addr = svm_set_tss_addr,
+
+   .hap_enabled = svm_hap_enabled,
 };
 
 static int __init svm_init(void)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 00a00e4..8feb775 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -2631,6 +2631,11 @@ static void __init vmx_check_processor_compat(void *rtn)
}
 }
 
+static bool vmx_hap_enabled(void)
+{
+   return false;
+}
+
 static struct kvm_x86_ops vmx_x86_ops = {
.cpu_has_kvm_support = cpu_has_kvm_support,
.disabled_by_bios = vmx_disabled_by_bios,
@@ -2688,6 +2693,8 @@ static struct kvm_x86_ops vmx_x86_ops = {
.inject_pending_vectors = do_interrupt_requests,
 
.set_tss_addr = vmx_set_tss_addr,
+
+   .hap_enabled = vmx_hap_enabled,
 };
 
 static int __init vmx_init(void)
diff --git a/include/asm-x86/kvm_host.h b/include/asm-x86/kvm_host.h
index 67ae307..45a9d05 100644
--- a/include/asm-x86/kvm_host.h
+++ b/include/asm-x86/kvm_host.h
@@ -392,6 +392,8 @@ struct kvm_x86_ops {
   struct kvm_run *run);
 
int (*set_tss_addr)(struct kvm *kvm, unsigned int addr);
+
+   bool (*hap_enabled)(void);
 };
 
 extern struct kvm_x86_ops *kvm_x86_ops;
-- 
1.5.3.7




-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 4/8] X86: export information about NPT to generic x86 code

2008-02-07 Thread Joerg Roedel
The generic x86 code has to know if the specific implementation uses Nested
Paging. In the generic code Nested Paging is called Two Dimensional Paging
(TDP) to avoid confusion with (future) TDP implementations of other vendors.
This patch exports the availability of TDP to the generic x86 code.

Signed-off-by: Joerg Roedel <[EMAIL PROTECTED]>
---
 arch/x86/kvm/mmu.c |   15 +++
 arch/x86/kvm/svm.c |4 +++-
 include/asm-x86/kvm_host.h |2 ++
 3 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 635e70c..3477395 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -32,6 +32,15 @@
 #include 
 #include 
 
+/*
+ * When setting this variable to true it enables Two-Dimensional-Paging
+ * where the hardware walks 2 page tables:
+ * 1. the guest-virtual to guest-physical
+ * 2. while doing 1. it walks guest-physical to host-physical
+ * If the hardware supports that we don't need to do shadow paging.
+ */
+static bool tdp_enabled = false;
+
 #undef MMU_DEBUG
 
 #undef AUDIT
@@ -1562,6 +1571,12 @@ out:
 }
 EXPORT_SYMBOL_GPL(kvm_mmu_page_fault);
 
+void kvm_enable_tdp(void)
+{
+   tdp_enabled = true;
+}
+EXPORT_SYMBOL_GPL(kvm_enable_tdp);
+
 static void free_mmu_pages(struct kvm_vcpu *vcpu)
 {
struct kvm_mmu_page *sp;
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 8173ba6..f400499 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -423,8 +423,10 @@ static __init int svm_hardware_setup(void)
npt_enabled = false;
}
 
-   if (npt_enabled)
+   if (npt_enabled) {
printk(KERN_INFO "kvm: Nested Paging enabled\n");
+   kvm_enable_tdp();
+   }
 
return 0;
 
diff --git a/include/asm-x86/kvm_host.h b/include/asm-x86/kvm_host.h
index 67ae307..7661da0 100644
--- a/include/asm-x86/kvm_host.h
+++ b/include/asm-x86/kvm_host.h
@@ -491,6 +491,8 @@ int kvm_fix_hypercall(struct kvm_vcpu *vcpu);
 
 int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t gva, u32 error_code);
 
+void kvm_enable_tdp(void);
+
 int load_pdptrs(struct kvm_vcpu *vcpu, unsigned long cr3);
 int complete_pio(struct kvm_vcpu *vcpu);
 
-- 
1.5.3.7




-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [PATCH 4/8] X86: export information about NPT to generic x86 code

2008-01-25 Thread Anthony Liguori
Joerg Roedel wrote:
> The generic x86 code has to know if the specific implementation uses Nested
> Paging. In the generic code Nested Paging is called Hardware Assisted Paging
> (HAP) to avoid confusion with (future) HAP implementations of other vendors.
> This patch exports the availability of HAP to the generic x86 code.
>
> Signed-off-by: Joerg Roedel <[EMAIL PROTECTED]>
> ---
>  arch/x86/kvm/svm.c |7 +++
>  arch/x86/kvm/vmx.c |7 +++
>  include/asm-x86/kvm_host.h |2 ++
>  3 files changed, 16 insertions(+), 0 deletions(-)
>
> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> index 2e718ff..d0bfdd8 100644
> --- a/arch/x86/kvm/svm.c
> +++ b/arch/x86/kvm/svm.c
> @@ -1678,6 +1678,11 @@ static bool svm_cpu_has_accelerated_tpr(void)
>   return false;
>  }
>  
> +static bool svm_hap_enabled(void)
> +{
> + return npt_enabled;
> +}
> +
>   

To help with bisecting, you should probably return false here until the 
patch that actually implements NPT support.  Otherwise, the 7th patch in 
this series breaks KVM for SVM.

Regards,

Anthony Liguori

>  static struct kvm_x86_ops svm_x86_ops = {
>   .cpu_has_kvm_support = has_svm,
>   .disabled_by_bios = is_disabled,
> @@ -1734,6 +1739,8 @@ static struct kvm_x86_ops svm_x86_ops = {
>   .inject_pending_vectors = do_interrupt_requests,
>  
>   .set_tss_addr = svm_set_tss_addr,
> +
> + .hap_enabled = svm_hap_enabled,
>  };
>  
>  static int __init svm_init(void)
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 00a00e4..8feb775 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -2631,6 +2631,11 @@ static void __init vmx_check_processor_compat(void 
> *rtn)
>   }
>  }
>  
> +static bool vmx_hap_enabled(void)
> +{
> + return false;
> +}
> +
>  static struct kvm_x86_ops vmx_x86_ops = {
>   .cpu_has_kvm_support = cpu_has_kvm_support,
>   .disabled_by_bios = vmx_disabled_by_bios,
> @@ -2688,6 +2693,8 @@ static struct kvm_x86_ops vmx_x86_ops = {
>   .inject_pending_vectors = do_interrupt_requests,
>  
>   .set_tss_addr = vmx_set_tss_addr,
> +
> + .hap_enabled = vmx_hap_enabled,
>  };
>  
>  static int __init vmx_init(void)
> diff --git a/include/asm-x86/kvm_host.h b/include/asm-x86/kvm_host.h
> index 67ae307..45a9d05 100644
> --- a/include/asm-x86/kvm_host.h
> +++ b/include/asm-x86/kvm_host.h
> @@ -392,6 +392,8 @@ struct kvm_x86_ops {
>  struct kvm_run *run);
>  
>   int (*set_tss_addr)(struct kvm *kvm, unsigned int addr);
> +
> + bool (*hap_enabled)(void);
>  };
>  
>  extern struct kvm_x86_ops *kvm_x86_ops;
>   


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [PATCH 4/8] X86: export information about NPT to generic x86 code

2008-01-25 Thread Anthony Liguori
Anthony Liguori wrote:
> Joerg Roedel wrote:
>> The generic x86 code has to know if the specific implementation uses 
>> Nested
>> Paging. In the generic code Nested Paging is called Hardware Assisted 
>> Paging
>> (HAP) to avoid confusion with (future) HAP implementations of other 
>> vendors.
>> This patch exports the availability of HAP to the generic x86 code.
>>
>> Signed-off-by: Joerg Roedel <[EMAIL PROTECTED]>
>> ---
>>  arch/x86/kvm/svm.c |7 +++
>>  arch/x86/kvm/vmx.c |7 +++
>>  include/asm-x86/kvm_host.h |2 ++
>>  3 files changed, 16 insertions(+), 0 deletions(-)
>>
>> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
>> index 2e718ff..d0bfdd8 100644
>> --- a/arch/x86/kvm/svm.c
>> +++ b/arch/x86/kvm/svm.c
>> @@ -1678,6 +1678,11 @@ static bool svm_cpu_has_accelerated_tpr(void)
>>  return false;
>>  }
>>  
>> +static bool svm_hap_enabled(void)
>> +{
>> +return npt_enabled;
>> +}
>> +
>>   
>
> To help with bisecting, you should probably return false here until 
> the patch that actually implements NPT support.  Otherwise, the 7th 
> patch in this series breaks KVM for SVM.

Ignore this, you're already doing the right thing :-)

Regards,

Anthony Liguori

> Regards,
>
> Anthony Liguori
>
>>  static struct kvm_x86_ops svm_x86_ops = {
>>  .cpu_has_kvm_support = has_svm,
>>  .disabled_by_bios = is_disabled,
>> @@ -1734,6 +1739,8 @@ static struct kvm_x86_ops svm_x86_ops = {
>>  .inject_pending_vectors = do_interrupt_requests,
>>  
>>  .set_tss_addr = svm_set_tss_addr,
>> +
>> +.hap_enabled = svm_hap_enabled,
>>  };
>>  
>>  static int __init svm_init(void)
>> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
>> index 00a00e4..8feb775 100644
>> --- a/arch/x86/kvm/vmx.c
>> +++ b/arch/x86/kvm/vmx.c
>> @@ -2631,6 +2631,11 @@ static void __init 
>> vmx_check_processor_compat(void *rtn)
>>  }
>>  }
>>  
>> +static bool vmx_hap_enabled(void)
>> +{
>> +return false;
>> +}
>> +
>>  static struct kvm_x86_ops vmx_x86_ops = {
>>  .cpu_has_kvm_support = cpu_has_kvm_support,
>>  .disabled_by_bios = vmx_disabled_by_bios,
>> @@ -2688,6 +2693,8 @@ static struct kvm_x86_ops vmx_x86_ops = {
>>  .inject_pending_vectors = do_interrupt_requests,
>>  
>>  .set_tss_addr = vmx_set_tss_addr,
>> +
>> +.hap_enabled = vmx_hap_enabled,
>>  };
>>  
>>  static int __init vmx_init(void)
>> diff --git a/include/asm-x86/kvm_host.h b/include/asm-x86/kvm_host.h
>> index 67ae307..45a9d05 100644
>> --- a/include/asm-x86/kvm_host.h
>> +++ b/include/asm-x86/kvm_host.h
>> @@ -392,6 +392,8 @@ struct kvm_x86_ops {
>> struct kvm_run *run);
>>  
>>  int (*set_tss_addr)(struct kvm *kvm, unsigned int addr);
>> +
>> +bool (*hap_enabled)(void);
>>  };
>>  
>>  extern struct kvm_x86_ops *kvm_x86_ops;
>>   
>


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [PATCH 4/8] X86: export information about NPT to generic x86 code

2008-01-27 Thread Avi Kivity
Joerg Roedel wrote:
> The generic x86 code has to know if the specific implementation uses Nested
> Paging. In the generic code Nested Paging is called Hardware Assisted Paging
> (HAP) to avoid confusion with (future) HAP implementations of other vendors.
> This patch exports the availability of HAP to the generic x86 code.
>
>   int (*set_tss_addr)(struct kvm *kvm, unsigned int addr);
> +
> + bool (*hap_enabled)(void);
>  };
>  
>   

Since the value doesn't change during the lifetime of the VM, it can be 
a data field instead of a function.  Or, if we find that npt/ept is 
always a win, a static field in mmu.c.

-- 
error compiling committee.c: too many arguments to function


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel