forked from Minki/linux
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>
This commit is contained in:
parent
1a18a69b76
commit
9d4cba7f93
@ -21,25 +21,6 @@
|
|||||||
#include <asm/synch.h>
|
#include <asm/synch.h>
|
||||||
#include <asm/ppc-opcode.h>
|
#include <asm/ppc-opcode.h>
|
||||||
|
|
||||||
/*
|
|
||||||
* Since this file is built in even if KVM is a module, we need
|
|
||||||
* a local copy of this function for the case where kvm_main.c is
|
|
||||||
* modular.
|
|
||||||
*/
|
|
||||||
static struct kvm_memory_slot *builtin_gfn_to_memslot(struct kvm *kvm,
|
|
||||||
gfn_t gfn)
|
|
||||||
{
|
|
||||||
struct kvm_memslots *slots;
|
|
||||||
struct kvm_memory_slot *memslot;
|
|
||||||
|
|
||||||
slots = kvm_memslots(kvm);
|
|
||||||
kvm_for_each_memslot(memslot, slots)
|
|
||||||
if (gfn >= memslot->base_gfn &&
|
|
||||||
gfn < memslot->base_gfn + memslot->npages)
|
|
||||||
return memslot;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Translate address of a vmalloc'd thing to a linear map address */
|
/* Translate address of a vmalloc'd thing to a linear map address */
|
||||||
static void *real_vmalloc_addr(void *x)
|
static void *real_vmalloc_addr(void *x)
|
||||||
{
|
{
|
||||||
@ -99,7 +80,7 @@ static void remove_revmap_chain(struct kvm *kvm, long pte_index,
|
|||||||
rcbits = hpte_r & (HPTE_R_R | HPTE_R_C);
|
rcbits = hpte_r & (HPTE_R_R | HPTE_R_C);
|
||||||
ptel = rev->guest_rpte |= rcbits;
|
ptel = rev->guest_rpte |= rcbits;
|
||||||
gfn = hpte_rpn(ptel, hpte_page_size(hpte_v, ptel));
|
gfn = hpte_rpn(ptel, hpte_page_size(hpte_v, ptel));
|
||||||
memslot = builtin_gfn_to_memslot(kvm, gfn);
|
memslot = __gfn_to_memslot(kvm_memslots(kvm), gfn);
|
||||||
if (!memslot || (memslot->flags & KVM_MEMSLOT_INVALID))
|
if (!memslot || (memslot->flags & KVM_MEMSLOT_INVALID))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -181,7 +162,7 @@ long kvmppc_h_enter(struct kvm_vcpu *vcpu, unsigned long flags,
|
|||||||
/* Find the memslot (if any) for this address */
|
/* Find the memslot (if any) for this address */
|
||||||
gpa = (ptel & HPTE_R_RPN) & ~(psize - 1);
|
gpa = (ptel & HPTE_R_RPN) & ~(psize - 1);
|
||||||
gfn = gpa >> PAGE_SHIFT;
|
gfn = gpa >> PAGE_SHIFT;
|
||||||
memslot = builtin_gfn_to_memslot(kvm, gfn);
|
memslot = __gfn_to_memslot(kvm_memslots(kvm), gfn);
|
||||||
pa = 0;
|
pa = 0;
|
||||||
is_io = ~0ul;
|
is_io = ~0ul;
|
||||||
rmap = NULL;
|
rmap = NULL;
|
||||||
|
@ -651,6 +651,31 @@ static inline void kvm_guest_exit(void)
|
|||||||
current->flags &= ~PF_VCPU;
|
current->flags &= ~PF_VCPU;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* search_memslots() and __gfn_to_memslot() are here because they are
|
||||||
|
* used in non-modular code in arch/powerpc/kvm/book3s_hv_rm_mmu.c.
|
||||||
|
* gfn_to_memslot() itself isn't here as an inline because that would
|
||||||
|
* bloat other code too much.
|
||||||
|
*/
|
||||||
|
static inline struct kvm_memory_slot *
|
||||||
|
search_memslots(struct kvm_memslots *slots, gfn_t gfn)
|
||||||
|
{
|
||||||
|
struct kvm_memory_slot *memslot;
|
||||||
|
|
||||||
|
kvm_for_each_memslot(memslot, slots)
|
||||||
|
if (gfn >= memslot->base_gfn &&
|
||||||
|
gfn < memslot->base_gfn + memslot->npages)
|
||||||
|
return memslot;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline struct kvm_memory_slot *
|
||||||
|
__gfn_to_memslot(struct kvm_memslots *slots, gfn_t gfn)
|
||||||
|
{
|
||||||
|
return search_memslots(slots, gfn);
|
||||||
|
}
|
||||||
|
|
||||||
static inline int memslot_id(struct kvm *kvm, gfn_t gfn)
|
static inline int memslot_id(struct kvm *kvm, gfn_t gfn)
|
||||||
{
|
{
|
||||||
return gfn_to_memslot(kvm, gfn)->id;
|
return gfn_to_memslot(kvm, gfn)->id;
|
||||||
|
@ -640,19 +640,6 @@ static int kvm_create_dirty_bitmap(struct kvm_memory_slot *memslot)
|
|||||||
}
|
}
|
||||||
#endif /* !CONFIG_S390 */
|
#endif /* !CONFIG_S390 */
|
||||||
|
|
||||||
static struct kvm_memory_slot *
|
|
||||||
search_memslots(struct kvm_memslots *slots, gfn_t gfn)
|
|
||||||
{
|
|
||||||
struct kvm_memory_slot *memslot;
|
|
||||||
|
|
||||||
kvm_for_each_memslot(memslot, slots)
|
|
||||||
if (gfn >= memslot->base_gfn &&
|
|
||||||
gfn < memslot->base_gfn + memslot->npages)
|
|
||||||
return memslot;
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int cmp_memslot(const void *slot1, const void *slot2)
|
static int cmp_memslot(const void *slot1, const void *slot2)
|
||||||
{
|
{
|
||||||
struct kvm_memory_slot *s1, *s2;
|
struct kvm_memory_slot *s1, *s2;
|
||||||
@ -1031,12 +1018,6 @@ int kvm_is_error_hva(unsigned long addr)
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(kvm_is_error_hva);
|
EXPORT_SYMBOL_GPL(kvm_is_error_hva);
|
||||||
|
|
||||||
static struct kvm_memory_slot *__gfn_to_memslot(struct kvm_memslots *slots,
|
|
||||||
gfn_t gfn)
|
|
||||||
{
|
|
||||||
return search_memslots(slots, gfn);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn)
|
struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn)
|
||||||
{
|
{
|
||||||
return __gfn_to_memslot(kvm_memslots(kvm), gfn);
|
return __gfn_to_memslot(kvm_memslots(kvm), gfn);
|
||||||
@ -1459,7 +1440,7 @@ int kvm_gfn_to_hva_cache_init(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
|
|||||||
|
|
||||||
ghc->gpa = gpa;
|
ghc->gpa = gpa;
|
||||||
ghc->generation = slots->generation;
|
ghc->generation = slots->generation;
|
||||||
ghc->memslot = __gfn_to_memslot(slots, gfn);
|
ghc->memslot = gfn_to_memslot(kvm, gfn);
|
||||||
ghc->hva = gfn_to_hva_many(ghc->memslot, gfn, NULL);
|
ghc->hva = gfn_to_hva_many(ghc->memslot, gfn, NULL);
|
||||||
if (!kvm_is_error_hva(ghc->hva))
|
if (!kvm_is_error_hva(ghc->hva))
|
||||||
ghc->hva += offset;
|
ghc->hva += offset;
|
||||||
|
Loading…
Reference in New Issue
Block a user