forked from luck/tmp_suning_uos_patched
KVM: Simplify kvm_free_memslot() and all its descendents
Now that all callers of kvm_free_memslot() pass NULL for @dont, remove the param from the top-level routine and all arch's implementations. No functional change intended. Tested-by: Christoffer Dall <christoffer.dall@arm.com> Reviewed-by: Peter Xu <peterx@redhat.com> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
5c0b4f3d5c
commit
e96c81ee89
|
@ -1133,7 +1133,7 @@ extern unsigned long kvm_mips_get_ramsize(struct kvm *kvm);
|
||||||
static inline void kvm_arch_hardware_unsetup(void) {}
|
static inline void kvm_arch_hardware_unsetup(void) {}
|
||||||
static inline void kvm_arch_sync_events(struct kvm *kvm) {}
|
static inline void kvm_arch_sync_events(struct kvm *kvm) {}
|
||||||
static inline void kvm_arch_free_memslot(struct kvm *kvm,
|
static inline void kvm_arch_free_memslot(struct kvm *kvm,
|
||||||
struct kvm_memory_slot *free, struct kvm_memory_slot *dont) {}
|
struct kvm_memory_slot *slot) {}
|
||||||
static inline void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen) {}
|
static inline void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen) {}
|
||||||
static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {}
|
static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {}
|
||||||
static inline void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu) {}
|
static inline void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu) {}
|
||||||
|
|
|
@ -200,8 +200,7 @@ extern void kvm_free_hpt_cma(struct page *page, unsigned long nr_pages);
|
||||||
extern int kvmppc_core_init_vm(struct kvm *kvm);
|
extern int kvmppc_core_init_vm(struct kvm *kvm);
|
||||||
extern void kvmppc_core_destroy_vm(struct kvm *kvm);
|
extern void kvmppc_core_destroy_vm(struct kvm *kvm);
|
||||||
extern void kvmppc_core_free_memslot(struct kvm *kvm,
|
extern void kvmppc_core_free_memslot(struct kvm *kvm,
|
||||||
struct kvm_memory_slot *free,
|
struct kvm_memory_slot *slot);
|
||||||
struct kvm_memory_slot *dont);
|
|
||||||
extern int kvmppc_core_prepare_memory_region(struct kvm *kvm,
|
extern int kvmppc_core_prepare_memory_region(struct kvm *kvm,
|
||||||
struct kvm_memory_slot *memslot,
|
struct kvm_memory_slot *memslot,
|
||||||
const struct kvm_userspace_memory_region *mem,
|
const struct kvm_userspace_memory_region *mem,
|
||||||
|
@ -291,8 +290,7 @@ struct kvmppc_ops {
|
||||||
int (*test_age_hva)(struct kvm *kvm, unsigned long hva);
|
int (*test_age_hva)(struct kvm *kvm, unsigned long hva);
|
||||||
void (*set_spte_hva)(struct kvm *kvm, unsigned long hva, pte_t pte);
|
void (*set_spte_hva)(struct kvm *kvm, unsigned long hva, pte_t pte);
|
||||||
void (*mmu_destroy)(struct kvm_vcpu *vcpu);
|
void (*mmu_destroy)(struct kvm_vcpu *vcpu);
|
||||||
void (*free_memslot)(struct kvm_memory_slot *free,
|
void (*free_memslot)(struct kvm_memory_slot *slot);
|
||||||
struct kvm_memory_slot *dont);
|
|
||||||
int (*init_vm)(struct kvm *kvm);
|
int (*init_vm)(struct kvm *kvm);
|
||||||
void (*destroy_vm)(struct kvm *kvm);
|
void (*destroy_vm)(struct kvm *kvm);
|
||||||
int (*get_smmu_info)(struct kvm *kvm, struct kvm_ppc_smmu_info *info);
|
int (*get_smmu_info)(struct kvm *kvm, struct kvm_ppc_smmu_info *info);
|
||||||
|
|
|
@ -804,10 +804,9 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log)
|
||||||
return kvm->arch.kvm_ops->get_dirty_log(kvm, log);
|
return kvm->arch.kvm_ops->get_dirty_log(kvm, log);
|
||||||
}
|
}
|
||||||
|
|
||||||
void kvmppc_core_free_memslot(struct kvm *kvm, struct kvm_memory_slot *free,
|
void kvmppc_core_free_memslot(struct kvm *kvm, struct kvm_memory_slot *slot)
|
||||||
struct kvm_memory_slot *dont)
|
|
||||||
{
|
{
|
||||||
kvm->arch.kvm_ops->free_memslot(free, dont);
|
kvm->arch.kvm_ops->free_memslot(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
void kvmppc_core_flush_memslot(struct kvm *kvm, struct kvm_memory_slot *memslot)
|
void kvmppc_core_flush_memslot(struct kvm *kvm, struct kvm_memory_slot *memslot)
|
||||||
|
|
|
@ -4447,13 +4447,10 @@ static int kvm_vm_ioctl_get_dirty_log_hv(struct kvm *kvm,
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void kvmppc_core_free_memslot_hv(struct kvm_memory_slot *free,
|
static void kvmppc_core_free_memslot_hv(struct kvm_memory_slot *slot)
|
||||||
struct kvm_memory_slot *dont)
|
|
||||||
{
|
{
|
||||||
if (!dont || free->arch.rmap != dont->arch.rmap) {
|
vfree(slot->arch.rmap);
|
||||||
vfree(free->arch.rmap);
|
slot->arch.rmap = NULL;
|
||||||
free->arch.rmap = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int kvmppc_core_prepare_memory_region_hv(struct kvm *kvm,
|
static int kvmppc_core_prepare_memory_region_hv(struct kvm *kvm,
|
||||||
|
|
|
@ -1942,8 +1942,7 @@ static void kvmppc_core_commit_memory_region_pr(struct kvm *kvm,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void kvmppc_core_free_memslot_pr(struct kvm_memory_slot *free,
|
static void kvmppc_core_free_memslot_pr(struct kvm_memory_slot *slot)
|
||||||
struct kvm_memory_slot *dont)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1771,8 +1771,7 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log)
|
||||||
return -ENOTSUPP;
|
return -ENOTSUPP;
|
||||||
}
|
}
|
||||||
|
|
||||||
void kvmppc_core_free_memslot(struct kvm *kvm, struct kvm_memory_slot *free,
|
void kvmppc_core_free_memslot(struct kvm *kvm, struct kvm_memory_slot *slot)
|
||||||
struct kvm_memory_slot *dont)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -685,10 +685,9 @@ long kvm_arch_dev_ioctl(struct file *filp,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *free,
|
void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *slot)
|
||||||
struct kvm_memory_slot *dont)
|
|
||||||
{
|
{
|
||||||
kvmppc_core_free_memslot(kvm, free, dont);
|
kvmppc_core_free_memslot(kvm, slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
int kvm_arch_prepare_memory_region(struct kvm *kvm,
|
int kvm_arch_prepare_memory_region(struct kvm *kvm,
|
||||||
|
|
|
@ -921,7 +921,7 @@ static inline void kvm_arch_hardware_disable(void) {}
|
||||||
static inline void kvm_arch_sync_events(struct kvm *kvm) {}
|
static inline void kvm_arch_sync_events(struct kvm *kvm) {}
|
||||||
static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {}
|
static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {}
|
||||||
static inline void kvm_arch_free_memslot(struct kvm *kvm,
|
static inline void kvm_arch_free_memslot(struct kvm *kvm,
|
||||||
struct kvm_memory_slot *free, struct kvm_memory_slot *dont) {}
|
struct kvm_memory_slot *slot) {}
|
||||||
static inline void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen) {}
|
static inline void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen) {}
|
||||||
static inline void kvm_arch_flush_shadow_all(struct kvm *kvm) {}
|
static inline void kvm_arch_flush_shadow_all(struct kvm *kvm) {}
|
||||||
static inline void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
|
static inline void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
|
||||||
|
|
|
@ -49,8 +49,7 @@ struct kvm_page_track_notifier_node {
|
||||||
void kvm_page_track_init(struct kvm *kvm);
|
void kvm_page_track_init(struct kvm *kvm);
|
||||||
void kvm_page_track_cleanup(struct kvm *kvm);
|
void kvm_page_track_cleanup(struct kvm *kvm);
|
||||||
|
|
||||||
void kvm_page_track_free_memslot(struct kvm_memory_slot *free,
|
void kvm_page_track_free_memslot(struct kvm_memory_slot *slot);
|
||||||
struct kvm_memory_slot *dont);
|
|
||||||
int kvm_page_track_create_memslot(struct kvm_memory_slot *slot,
|
int kvm_page_track_create_memslot(struct kvm_memory_slot *slot,
|
||||||
unsigned long npages);
|
unsigned long npages);
|
||||||
|
|
||||||
|
|
|
@ -19,17 +19,14 @@
|
||||||
|
|
||||||
#include "mmu.h"
|
#include "mmu.h"
|
||||||
|
|
||||||
void kvm_page_track_free_memslot(struct kvm_memory_slot *free,
|
void kvm_page_track_free_memslot(struct kvm_memory_slot *slot)
|
||||||
struct kvm_memory_slot *dont)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < KVM_PAGE_TRACK_MAX; i++)
|
for (i = 0; i < KVM_PAGE_TRACK_MAX; i++) {
|
||||||
if (!dont || free->arch.gfn_track[i] !=
|
kvfree(slot->arch.gfn_track[i]);
|
||||||
dont->arch.gfn_track[i]) {
|
slot->arch.gfn_track[i] = NULL;
|
||||||
kvfree(free->arch.gfn_track[i]);
|
}
|
||||||
free->arch.gfn_track[i] = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int kvm_page_track_create_memslot(struct kvm_memory_slot *slot,
|
int kvm_page_track_create_memslot(struct kvm_memory_slot *slot,
|
||||||
|
@ -48,7 +45,7 @@ int kvm_page_track_create_memslot(struct kvm_memory_slot *slot,
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
track_free:
|
track_free:
|
||||||
kvm_page_track_free_memslot(slot, NULL);
|
kvm_page_track_free_memslot(slot);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9850,27 +9850,22 @@ void kvm_arch_destroy_vm(struct kvm *kvm)
|
||||||
kvm_hv_destroy_vm(kvm);
|
kvm_hv_destroy_vm(kvm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *free,
|
void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *slot)
|
||||||
struct kvm_memory_slot *dont)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < KVM_NR_PAGE_SIZES; ++i) {
|
for (i = 0; i < KVM_NR_PAGE_SIZES; ++i) {
|
||||||
if (!dont || free->arch.rmap[i] != dont->arch.rmap[i]) {
|
kvfree(slot->arch.rmap[i]);
|
||||||
kvfree(free->arch.rmap[i]);
|
slot->arch.rmap[i] = NULL;
|
||||||
free->arch.rmap[i] = NULL;
|
|
||||||
}
|
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!dont || free->arch.lpage_info[i - 1] !=
|
kvfree(slot->arch.lpage_info[i - 1]);
|
||||||
dont->arch.lpage_info[i - 1]) {
|
slot->arch.lpage_info[i - 1] = NULL;
|
||||||
kvfree(free->arch.lpage_info[i - 1]);
|
|
||||||
free->arch.lpage_info[i - 1] = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
kvm_page_track_free_memslot(free, dont);
|
kvm_page_track_free_memslot(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int kvm_alloc_memslot_metadata(struct kvm_memory_slot *slot,
|
static int kvm_alloc_memslot_metadata(struct kvm_memory_slot *slot,
|
||||||
|
@ -10069,7 +10064,7 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
|
||||||
|
|
||||||
/* Free the arrays associated with the old memslot. */
|
/* Free the arrays associated with the old memslot. */
|
||||||
if (change == KVM_MR_MOVE)
|
if (change == KVM_MR_MOVE)
|
||||||
kvm_arch_free_memslot(kvm, old, NULL);
|
kvm_arch_free_memslot(kvm, old);
|
||||||
}
|
}
|
||||||
|
|
||||||
void kvm_arch_flush_shadow_all(struct kvm *kvm)
|
void kvm_arch_flush_shadow_all(struct kvm *kvm)
|
||||||
|
|
|
@ -669,8 +669,7 @@ int kvm_set_memory_region(struct kvm *kvm,
|
||||||
const struct kvm_userspace_memory_region *mem);
|
const struct kvm_userspace_memory_region *mem);
|
||||||
int __kvm_set_memory_region(struct kvm *kvm,
|
int __kvm_set_memory_region(struct kvm *kvm,
|
||||||
const struct kvm_userspace_memory_region *mem);
|
const struct kvm_userspace_memory_region *mem);
|
||||||
void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *free,
|
void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *slot);
|
||||||
struct kvm_memory_slot *dont);
|
|
||||||
void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen);
|
void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen);
|
||||||
int kvm_arch_prepare_memory_region(struct kvm *kvm,
|
int kvm_arch_prepare_memory_region(struct kvm *kvm,
|
||||||
struct kvm_memory_slot *memslot,
|
struct kvm_memory_slot *memslot,
|
||||||
|
|
|
@ -2349,8 +2349,7 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *free,
|
void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *slot)
|
||||||
struct kvm_memory_slot *dont)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -580,18 +580,14 @@ static void kvm_destroy_dirty_bitmap(struct kvm_memory_slot *memslot)
|
||||||
memslot->dirty_bitmap = NULL;
|
memslot->dirty_bitmap = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
static void kvm_free_memslot(struct kvm *kvm, struct kvm_memory_slot *slot)
|
||||||
* Free any memory in @free but not in @dont.
|
|
||||||
*/
|
|
||||||
static void kvm_free_memslot(struct kvm *kvm, struct kvm_memory_slot *free,
|
|
||||||
struct kvm_memory_slot *dont)
|
|
||||||
{
|
{
|
||||||
if (!dont || free->dirty_bitmap != dont->dirty_bitmap)
|
kvm_destroy_dirty_bitmap(slot);
|
||||||
kvm_destroy_dirty_bitmap(free);
|
|
||||||
|
|
||||||
kvm_arch_free_memslot(kvm, free, dont);
|
kvm_arch_free_memslot(kvm, slot);
|
||||||
|
|
||||||
free->npages = 0;
|
slot->flags = 0;
|
||||||
|
slot->npages = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void kvm_free_memslots(struct kvm *kvm, struct kvm_memslots *slots)
|
static void kvm_free_memslots(struct kvm *kvm, struct kvm_memslots *slots)
|
||||||
|
@ -602,7 +598,7 @@ static void kvm_free_memslots(struct kvm *kvm, struct kvm_memslots *slots)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
kvm_for_each_memslot(memslot, slots)
|
kvm_for_each_memslot(memslot, slots)
|
||||||
kvm_free_memslot(kvm, memslot, NULL);
|
kvm_free_memslot(kvm, memslot);
|
||||||
|
|
||||||
kvfree(slots);
|
kvfree(slots);
|
||||||
}
|
}
|
||||||
|
@ -1060,7 +1056,7 @@ static int kvm_delete_memslot(struct kvm *kvm,
|
||||||
if (r)
|
if (r)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
kvm_free_memslot(kvm, old, NULL);
|
kvm_free_memslot(kvm, old);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user