diff options
author | Paul Mackerras <paulus@samba.org> | 2012-01-12 15:09:51 -0500 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2012-03-05 07:57:22 -0500 |
commit | 9d4cba7f93c52d4121ab9c6f289e582d368a6979 (patch) | |
tree | 482c7d42dcf6921cf82cd54c51c5d0f07b64b748 /include/linux/kvm_host.h | |
parent | 1a18a69b762374c423305772500f36eb8984ca52 (diff) |
KVM: Move gfn_to_memslot() to kvm_host.h
This moves __gfn_to_memslot() and search_memslots() from kvm_main.c to
kvm_host.h to reduce the code duplication caused by the need for
non-modular code in arch/powerpc/kvm/book3s_hv_rm_mmu.c to call
gfn_to_memslot() in real mode.
Rather than putting gfn_to_memslot() itself in a header, which would
lead to increased code size, this puts __gfn_to_memslot() in a header.
Then, the non-modular uses of gfn_to_memslot() are changed to call
__gfn_to_memslot() instead. This way there is only one place in the
source code that needs to be changed should the gfn_to_memslot()
implementation need to be modified.
On powerpc, the Book3S HV style of KVM has code that is called from
real mode which needs to call gfn_to_memslot() and thus needs this.
(Module code is allocated in the vmalloc region, which can't be
accessed in real mode.)
With this, we can remove builtin_gfn_to_memslot() from book3s_hv_rm_mmu.c.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Acked-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'include/linux/kvm_host.h')
-rw-r--r-- | include/linux/kvm_host.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index eada8e69fe58..9698080c902b 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h | |||
@@ -651,6 +651,31 @@ static inline void kvm_guest_exit(void) | |||
651 | current->flags &= ~PF_VCPU; | 651 | current->flags &= ~PF_VCPU; |
652 | } | 652 | } |
653 | 653 | ||
654 | /* | ||
655 | * search_memslots() and __gfn_to_memslot() are here because they are | ||
656 | * used in non-modular code in arch/powerpc/kvm/book3s_hv_rm_mmu.c. | ||
657 | * gfn_to_memslot() itself isn't here as an inline because that would | ||
658 | * bloat other code too much. | ||
659 | */ | ||
660 | static inline struct kvm_memory_slot * | ||
661 | search_memslots(struct kvm_memslots *slots, gfn_t gfn) | ||
662 | { | ||
663 | struct kvm_memory_slot *memslot; | ||
664 | |||
665 | kvm_for_each_memslot(memslot, slots) | ||
666 | if (gfn >= memslot->base_gfn && | ||
667 | gfn < memslot->base_gfn + memslot->npages) | ||
668 | return memslot; | ||
669 | |||
670 | return NULL; | ||
671 | } | ||
672 | |||
673 | static inline struct kvm_memory_slot * | ||
674 | __gfn_to_memslot(struct kvm_memslots *slots, gfn_t gfn) | ||
675 | { | ||
676 | return search_memslots(slots, gfn); | ||
677 | } | ||
678 | |||
654 | static inline int memslot_id(struct kvm *kvm, gfn_t gfn) | 679 | static inline int memslot_id(struct kvm *kvm, gfn_t gfn) |
655 | { | 680 | { |
656 | return gfn_to_memslot(kvm, gfn)->id; | 681 | return gfn_to_memslot(kvm, gfn)->id; |