Re: [PATCH v4 14/14] KVM/nVMX: Use kvm_vcpu_map for accessing the enhanced VMCS

2018-12-06 Thread Vitaly Kuznetsov
KarimAllah Ahmed  writes:

> Use kvm_vcpu_map for accessing the enhanced VMCS since using

just a nitpick: "eVMCS" stands for Enlightened VMCS, not 'enhanced' :-)

> kvm_vcpu_gpa_to_page() and kmap() will only work for guest memory that has
> a "struct page".
>
> Signed-off-by: KarimAllah Ahmed 
> ---
>  arch/x86/kvm/vmx.c | 16 ++--
>  1 file changed, 6 insertions(+), 10 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index a958700..83a614f 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -894,7 +894,7 @@ struct nested_vmx {
>   } smm;
>  
>   gpa_t hv_evmcs_vmptr;
> - struct page *hv_evmcs_page;
> + struct kvm_host_map hv_evmcs_map;
>   struct hv_enlightened_vmcs *hv_evmcs;
>  };
>  
> @@ -8456,10 +8456,8 @@ static inline void nested_release_evmcs(struct 
> kvm_vcpu *vcpu)
>   if (!vmx->nested.hv_evmcs)
>   return;
>  
> - kunmap(vmx->nested.hv_evmcs_page);
> - kvm_release_page_dirty(vmx->nested.hv_evmcs_page);
> + kvm_vcpu_unmap(&vmx->nested.hv_evmcs_map);
>   vmx->nested.hv_evmcs_vmptr = -1ull;
> - vmx->nested.hv_evmcs_page = NULL;
>   vmx->nested.hv_evmcs = NULL;
>  }
>  
> @@ -8559,7 +8557,7 @@ static int handle_vmclear(struct kvm_vcpu *vcpu)
>   return nested_vmx_failValid(vcpu,
>   VMXERR_VMCLEAR_VMXON_POINTER);
>  
> - if (vmx->nested.hv_evmcs_page) {
> + if (vmx->nested.hv_evmcs_map.hva) {
>   if (vmptr == vmx->nested.hv_evmcs_vmptr)
>   nested_release_evmcs(vcpu);
>   } else {
> @@ -9355,13 +9353,11 @@ static int 
> nested_vmx_handle_enlightened_vmptrld(struct kvm_vcpu *vcpu,
>  
>   nested_release_evmcs(vcpu);
>  
> - vmx->nested.hv_evmcs_page = kvm_vcpu_gpa_to_page(
> - vcpu, assist_page.current_nested_vmcs);
> -
> - if (unlikely(is_error_page(vmx->nested.hv_evmcs_page)))
> + if (kvm_vcpu_map(vcpu, 
> gpa_to_gfn(assist_page.current_nested_vmcs),
> +  &vmx->nested.hv_evmcs_map))
>   return 0;
>  
> - vmx->nested.hv_evmcs = kmap(vmx->nested.hv_evmcs_page);
> + vmx->nested.hv_evmcs = vmx->nested.hv_evmcs_map.hva;
>  
>   /*
>* Currently, KVM only supports eVMCS version 1

-- 
Vitaly


[PATCH v4 14/14] KVM/nVMX: Use kvm_vcpu_map for accessing the enhanced VMCS

2018-12-03 Thread KarimAllah Ahmed
Use kvm_vcpu_map for accessing the enhanced VMCS since using
kvm_vcpu_gpa_to_page() and kmap() will only work for guest memory that has
a "struct page".

Signed-off-by: KarimAllah Ahmed 
---
 arch/x86/kvm/vmx.c | 16 ++--
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index a958700..83a614f 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -894,7 +894,7 @@ struct nested_vmx {
} smm;
 
gpa_t hv_evmcs_vmptr;
-   struct page *hv_evmcs_page;
+   struct kvm_host_map hv_evmcs_map;
struct hv_enlightened_vmcs *hv_evmcs;
 };
 
@@ -8456,10 +8456,8 @@ static inline void nested_release_evmcs(struct kvm_vcpu 
*vcpu)
if (!vmx->nested.hv_evmcs)
return;
 
-   kunmap(vmx->nested.hv_evmcs_page);
-   kvm_release_page_dirty(vmx->nested.hv_evmcs_page);
+   kvm_vcpu_unmap(&vmx->nested.hv_evmcs_map);
vmx->nested.hv_evmcs_vmptr = -1ull;
-   vmx->nested.hv_evmcs_page = NULL;
vmx->nested.hv_evmcs = NULL;
 }
 
@@ -8559,7 +8557,7 @@ static int handle_vmclear(struct kvm_vcpu *vcpu)
return nested_vmx_failValid(vcpu,
VMXERR_VMCLEAR_VMXON_POINTER);
 
-   if (vmx->nested.hv_evmcs_page) {
+   if (vmx->nested.hv_evmcs_map.hva) {
if (vmptr == vmx->nested.hv_evmcs_vmptr)
nested_release_evmcs(vcpu);
} else {
@@ -9355,13 +9353,11 @@ static int nested_vmx_handle_enlightened_vmptrld(struct 
kvm_vcpu *vcpu,
 
nested_release_evmcs(vcpu);
 
-   vmx->nested.hv_evmcs_page = kvm_vcpu_gpa_to_page(
-   vcpu, assist_page.current_nested_vmcs);
-
-   if (unlikely(is_error_page(vmx->nested.hv_evmcs_page)))
+   if (kvm_vcpu_map(vcpu, 
gpa_to_gfn(assist_page.current_nested_vmcs),
+&vmx->nested.hv_evmcs_map))
return 0;
 
-   vmx->nested.hv_evmcs = kmap(vmx->nested.hv_evmcs_page);
+   vmx->nested.hv_evmcs = vmx->nested.hv_evmcs_map.hva;
 
/*
 * Currently, KVM only supports eVMCS version 1
-- 
2.7.4