On Tuesday 14 August 2007 09:37:45 Gregory Haskins wrote:
> Signed-off-by: Gregory Haskins <[EMAIL PROTECTED]>
> ---
>
>  drivers/kvm/kvm.h |    1 +
>  drivers/kvm/mmu.c |   12 ++++++++++++
>  2 files changed, 13 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
> index 9934f11..05d5be1 100755
> --- a/drivers/kvm/kvm.h
> +++ b/drivers/kvm/kvm.h
> @@ -475,6 +475,7 @@ void vcpu_load(struct kvm_vcpu *vcpu);
>  void vcpu_put(struct kvm_vcpu *vcpu);
>
>  hpa_t gpa_to_hpa(struct kvm_vcpu *vcpu, gpa_t gpa);
> +void* gpa_to_hva(struct kvm *kvm, gpa_t gpa);
>  #define HPA_MSB ((sizeof(hpa_t) * 8) - 1)
>  #define HPA_ERR_MASK ((hpa_t)1 << HPA_MSB)
>  static inline int is_error_hpa(hpa_t hpa) { return hpa >> HPA_MSB; }
> diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
> index e84c599..daaf0d2 100644
> --- a/drivers/kvm/mmu.c
> +++ b/drivers/kvm/mmu.c
> @@ -766,6 +766,18 @@ hpa_t gpa_to_hpa(struct kvm_vcpu *vcpu, gpa_t gpa)
>  }
>  EXPORT_SYMBOL_GPL(gpa_to_hpa);
>
> +void* gpa_to_hva(struct kvm *kvm, gpa_t gpa)
> +{
> +     struct page *page;
> +
> +     if ((gpa & HPA_ERR_MASK) == 0)
> +             return NULL;
> +
> +     page = gfn_to_page(kvm, gpa >> PAGE_SHIFT);
> +     return kmap_atomic(page, gpa & PAGE_MASK);
> +}
> +EXPORT_SYMBOL_GPL(gpa_to_hva);
> +
>  hpa_t gva_to_hpa(struct kvm_vcpu *vcpu, gva_t gva)
>  {
>       gpa_t gpa = vcpu->mmu.gva_to_gpa(vcpu, gva);

There are several things about this patch which aren't nice:
- It implicitly does a kmap_atomic. That's a bad thing for procedures that 
might sleep after calling this
- It's prone to not being kunmapped
- kmap_atomic takes two arguments
- 'page' is not checked for !NULL
- we can simply use gpa_to_hpa and get page_address(hpa), instead of 
duplicating all that it does.

Amit.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel

Reply via email to