KVM: introduce kvm_read_guest_offset_cached()

We already have kvm_write_guest_offset_cached(), introduce read analogue.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Message-Id: <20200525144125.143875-5-vkuznets@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Vitaly Kuznetsov 2020-05-25 16:41:19 +02:00 committed by Paolo Bonzini
parent 7c0ade6c90
commit 0958f0cefe
2 changed files with 17 additions and 5 deletions

View File

@ -734,6 +734,9 @@ int kvm_read_guest_page(struct kvm *kvm, gfn_t gfn, void *data, int offset,
int kvm_read_guest(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len); int kvm_read_guest(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len);
int kvm_read_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc, int kvm_read_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
void *data, unsigned long len); void *data, unsigned long len);
int kvm_read_guest_offset_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
void *data, unsigned int offset,
unsigned long len);
int kvm_write_guest_page(struct kvm *kvm, gfn_t gfn, const void *data, int kvm_write_guest_page(struct kvm *kvm, gfn_t gfn, const void *data,
int offset, int len); int offset, int len);
int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data, int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data,

View File

@ -2510,13 +2510,15 @@ int kvm_write_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
} }
EXPORT_SYMBOL_GPL(kvm_write_guest_cached); EXPORT_SYMBOL_GPL(kvm_write_guest_cached);
int kvm_read_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc, int kvm_read_guest_offset_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
void *data, unsigned long len) void *data, unsigned int offset,
unsigned long len)
{ {
struct kvm_memslots *slots = kvm_memslots(kvm); struct kvm_memslots *slots = kvm_memslots(kvm);
int r; int r;
gpa_t gpa = ghc->gpa + offset;
BUG_ON(len > ghc->len); BUG_ON(len + offset > ghc->len);
if (slots->generation != ghc->generation) { if (slots->generation != ghc->generation) {
if (__kvm_gfn_to_hva_cache_init(slots, ghc, ghc->gpa, ghc->len)) if (__kvm_gfn_to_hva_cache_init(slots, ghc, ghc->gpa, ghc->len))
@ -2527,14 +2529,21 @@ int kvm_read_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
return -EFAULT; return -EFAULT;
if (unlikely(!ghc->memslot)) if (unlikely(!ghc->memslot))
return kvm_read_guest(kvm, ghc->gpa, data, len); return kvm_read_guest(kvm, gpa, data, len);
r = __copy_from_user(data, (void __user *)ghc->hva, len); r = __copy_from_user(data, (void __user *)ghc->hva + offset, len);
if (r) if (r)
return -EFAULT; return -EFAULT;
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(kvm_read_guest_offset_cached);
int kvm_read_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
void *data, unsigned long len)
{
return kvm_read_guest_offset_cached(kvm, ghc, data, 0, len);
}
EXPORT_SYMBOL_GPL(kvm_read_guest_cached); EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len) int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)