mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-10-31 22:34:33 +01:00
kvm: Introduce kvm_write_guest_offset_cached()
It allows us to update some status or field of a structure partially. We can also save a kvm_read_guest_cached() call if we just update one fild of the struct regardless of its current value. Signed-off-by: Pan Xinhui <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Paolo Bonzini <[email protected]> Cc: [email protected] Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] [ Typo fixes. ] Signed-off-by: Ingo Molnar <[email protected]>
This commit is contained in:
1 parent
446f3dc8cc
commit
4ec6e86362
2 files changed
+16
-6
No files matched your search
@@ -645,6 +645,8 @@ int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data,
|
||||
unsigned long len);
|
||||
int kvm_write_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
|
||||
void *data, unsigned long len);
|
||||
int kvm_write_guest_offset_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
|
||||
void *data, int offset, unsigned long len);
|
||||
int kvm_gfn_to_hva_cache_init(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
|
||||
gpa_t gpa, unsigned long len);
|
||||
int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len);
|
||||
|
||||
+14
-6
@@ -1972,30 +1972,38 @@ int kvm_gfn_to_hva_cache_init(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(kvm_gfn_to_hva_cache_init);
|
||||
|
||||
int kvm_write_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
|
||||
void *data, unsigned long len)
|
||||
int kvm_write_guest_offset_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
|
||||
void *data, int offset, unsigned long len)
|
||||
{
|
||||
struct kvm_memslots *slots = kvm_memslots(kvm);
|
||||
int r;
|
||||
gpa_t gpa = ghc->gpa + offset;
|
||||
|
||||
BUG_ON(len > ghc->len);
|
||||
BUG_ON(len + offset > ghc->len);
|
||||
|
||||
if (slots->generation != ghc->generation)
|
||||
kvm_gfn_to_hva_cache_init(kvm, ghc, ghc->gpa, ghc->len);
|
||||
|
||||
if (unlikely(!ghc->memslot))
|
||||
return kvm_write_guest(kvm, ghc->gpa, data, len);
|
||||
return kvm_write_guest(kvm, gpa, data, len);
|
||||
|
||||
if (kvm_is_error_hva(ghc->hva))
|
||||
return -EFAULT;
|
||||
|
||||
r = __copy_to_user((void __user *)ghc->hva, data, len);
|
||||
r = __copy_to_user((void __user *)ghc->hva + offset, data, len);
|
||||
if (r)
|
||||
return -EFAULT;
|
||||
mark_page_dirty_in_slot(ghc->memslot, ghc->gpa >> PAGE_SHIFT);
|
||||
mark_page_dirty_in_slot(ghc->memslot, gpa >> PAGE_SHIFT);
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(kvm_write_guest_offset_cached);
|
||||
|
||||
int kvm_write_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
|
||||
void *data, unsigned long len)
|
||||
{
|
||||
return kvm_write_guest_offset_cached(kvm, ghc, data, 0, len);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(kvm_write_guest_cached);
|
||||
|
||||
int kvm_read_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
|
||||
|
||||
Reference in new issue
Block a user