Commit eaaaed13 authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: PPC: Avoid referencing userspace memory region in memslot updates

For PPC HV, get the number of pages directly from the new memslot instead
of computing the same from the userspace memory region, and explicitly
check for !DELETE instead of inferring the same when toggling mmio_update.
The motivation for these changes is to avoid referencing the @mem param
so that it can be dropped in a future commit.

No functional change intended.
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarMaciej S. Szmigiero <maciej.szmigiero@oracle.com>
Message-Id: <1e97fb5198be25f98ef82e63a8d770c682264cc9.1638817639.git.maciej.szmigiero@oracle.com>
parent 3b181617
...@@ -200,12 +200,10 @@ extern void kvmppc_core_destroy_vm(struct kvm *kvm); ...@@ -200,12 +200,10 @@ 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 *slot); struct kvm_memory_slot *slot);
extern int kvmppc_core_prepare_memory_region(struct kvm *kvm, extern int kvmppc_core_prepare_memory_region(struct kvm *kvm,
const struct kvm_userspace_memory_region *mem,
const struct kvm_memory_slot *old, const struct kvm_memory_slot *old,
struct kvm_memory_slot *new, struct kvm_memory_slot *new,
enum kvm_mr_change change); enum kvm_mr_change change);
extern void kvmppc_core_commit_memory_region(struct kvm *kvm, extern void kvmppc_core_commit_memory_region(struct kvm *kvm,
const struct kvm_userspace_memory_region *mem,
struct kvm_memory_slot *old, struct kvm_memory_slot *old,
const struct kvm_memory_slot *new, const struct kvm_memory_slot *new,
enum kvm_mr_change change); enum kvm_mr_change change);
...@@ -275,12 +273,10 @@ struct kvmppc_ops { ...@@ -275,12 +273,10 @@ struct kvmppc_ops {
int (*get_dirty_log)(struct kvm *kvm, struct kvm_dirty_log *log); int (*get_dirty_log)(struct kvm *kvm, struct kvm_dirty_log *log);
void (*flush_memslot)(struct kvm *kvm, struct kvm_memory_slot *memslot); void (*flush_memslot)(struct kvm *kvm, struct kvm_memory_slot *memslot);
int (*prepare_memory_region)(struct kvm *kvm, int (*prepare_memory_region)(struct kvm *kvm,
const struct kvm_userspace_memory_region *mem,
const struct kvm_memory_slot *old, const struct kvm_memory_slot *old,
struct kvm_memory_slot *new, struct kvm_memory_slot *new,
enum kvm_mr_change change); enum kvm_mr_change change);
void (*commit_memory_region)(struct kvm *kvm, void (*commit_memory_region)(struct kvm *kvm,
const struct kvm_userspace_memory_region *mem,
struct kvm_memory_slot *old, struct kvm_memory_slot *old,
const struct kvm_memory_slot *new, const struct kvm_memory_slot *new,
enum kvm_mr_change change); enum kvm_mr_change change);
......
...@@ -847,21 +847,19 @@ void kvmppc_core_flush_memslot(struct kvm *kvm, struct kvm_memory_slot *memslot) ...@@ -847,21 +847,19 @@ void kvmppc_core_flush_memslot(struct kvm *kvm, struct kvm_memory_slot *memslot)
} }
int kvmppc_core_prepare_memory_region(struct kvm *kvm, int kvmppc_core_prepare_memory_region(struct kvm *kvm,
const struct kvm_userspace_memory_region *mem,
const struct kvm_memory_slot *old, const struct kvm_memory_slot *old,
struct kvm_memory_slot *new, struct kvm_memory_slot *new,
enum kvm_mr_change change) enum kvm_mr_change change)
{ {
return kvm->arch.kvm_ops->prepare_memory_region(kvm, mem, old, new, change); return kvm->arch.kvm_ops->prepare_memory_region(kvm, old, new, change);
} }
void kvmppc_core_commit_memory_region(struct kvm *kvm, void kvmppc_core_commit_memory_region(struct kvm *kvm,
const struct kvm_userspace_memory_region *mem,
struct kvm_memory_slot *old, struct kvm_memory_slot *old,
const struct kvm_memory_slot *new, const struct kvm_memory_slot *new,
enum kvm_mr_change change) enum kvm_mr_change change)
{ {
kvm->arch.kvm_ops->commit_memory_region(kvm, mem, old, new, change); kvm->arch.kvm_ops->commit_memory_region(kvm, old, new, change);
} }
bool kvm_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range) bool kvm_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range)
......
...@@ -4854,15 +4854,12 @@ static void kvmppc_core_free_memslot_hv(struct kvm_memory_slot *slot) ...@@ -4854,15 +4854,12 @@ static void kvmppc_core_free_memslot_hv(struct kvm_memory_slot *slot)
} }
static int kvmppc_core_prepare_memory_region_hv(struct kvm *kvm, static int kvmppc_core_prepare_memory_region_hv(struct kvm *kvm,
const struct kvm_userspace_memory_region *mem,
const struct kvm_memory_slot *old, const struct kvm_memory_slot *old,
struct kvm_memory_slot *new, struct kvm_memory_slot *new,
enum kvm_mr_change change) enum kvm_mr_change change)
{ {
unsigned long npages = mem->memory_size >> PAGE_SHIFT;
if (change == KVM_MR_CREATE) { if (change == KVM_MR_CREATE) {
new->arch.rmap = vzalloc(array_size(npages, new->arch.rmap = vzalloc(array_size(new->npages,
sizeof(*new->arch.rmap))); sizeof(*new->arch.rmap)));
if (!new->arch.rmap) if (!new->arch.rmap)
return -ENOMEM; return -ENOMEM;
...@@ -4874,20 +4871,17 @@ static int kvmppc_core_prepare_memory_region_hv(struct kvm *kvm, ...@@ -4874,20 +4871,17 @@ static int kvmppc_core_prepare_memory_region_hv(struct kvm *kvm,
} }
static void kvmppc_core_commit_memory_region_hv(struct kvm *kvm, static void kvmppc_core_commit_memory_region_hv(struct kvm *kvm,
const struct kvm_userspace_memory_region *mem,
struct kvm_memory_slot *old, struct kvm_memory_slot *old,
const struct kvm_memory_slot *new, const struct kvm_memory_slot *new,
enum kvm_mr_change change) enum kvm_mr_change change)
{ {
unsigned long npages = mem->memory_size >> PAGE_SHIFT;
/* /*
* If we are making a new memslot, it might make * If we are creating or modifying a memslot, it might make
* some address that was previously cached as emulated * some address that was previously cached as emulated
* MMIO be no longer emulated MMIO, so invalidate * MMIO be no longer emulated MMIO, so invalidate
* all the caches of emulated MMIO translations. * all the caches of emulated MMIO translations.
*/ */
if (npages) if (change != KVM_MR_DELETE)
atomic64_inc(&kvm->arch.mmio_update); atomic64_inc(&kvm->arch.mmio_update);
/* /*
......
...@@ -1899,7 +1899,6 @@ static void kvmppc_core_flush_memslot_pr(struct kvm *kvm, ...@@ -1899,7 +1899,6 @@ static void kvmppc_core_flush_memslot_pr(struct kvm *kvm,
} }
static int kvmppc_core_prepare_memory_region_pr(struct kvm *kvm, static int kvmppc_core_prepare_memory_region_pr(struct kvm *kvm,
const struct kvm_userspace_memory_region *mem,
const struct kvm_memory_slot *old, const struct kvm_memory_slot *old,
struct kvm_memory_slot *new, struct kvm_memory_slot *new,
enum kvm_mr_change change) enum kvm_mr_change change)
...@@ -1908,7 +1907,6 @@ static int kvmppc_core_prepare_memory_region_pr(struct kvm *kvm, ...@@ -1908,7 +1907,6 @@ static int kvmppc_core_prepare_memory_region_pr(struct kvm *kvm,
} }
static void kvmppc_core_commit_memory_region_pr(struct kvm *kvm, static void kvmppc_core_commit_memory_region_pr(struct kvm *kvm,
const struct kvm_userspace_memory_region *mem,
struct kvm_memory_slot *old, struct kvm_memory_slot *old,
const struct kvm_memory_slot *new, const struct kvm_memory_slot *new,
enum kvm_mr_change change) enum kvm_mr_change change)
......
...@@ -1821,7 +1821,6 @@ void kvmppc_core_free_memslot(struct kvm *kvm, struct kvm_memory_slot *slot) ...@@ -1821,7 +1821,6 @@ void kvmppc_core_free_memslot(struct kvm *kvm, struct kvm_memory_slot *slot)
} }
int kvmppc_core_prepare_memory_region(struct kvm *kvm, int kvmppc_core_prepare_memory_region(struct kvm *kvm,
const struct kvm_userspace_memory_region *mem,
const struct kvm_memory_slot *old, const struct kvm_memory_slot *old,
struct kvm_memory_slot *new, struct kvm_memory_slot *new,
enum kvm_mr_change change) enum kvm_mr_change change)
...@@ -1830,7 +1829,6 @@ int kvmppc_core_prepare_memory_region(struct kvm *kvm, ...@@ -1830,7 +1829,6 @@ int kvmppc_core_prepare_memory_region(struct kvm *kvm,
} }
void kvmppc_core_commit_memory_region(struct kvm *kvm, void kvmppc_core_commit_memory_region(struct kvm *kvm,
const struct kvm_userspace_memory_region *mem,
struct kvm_memory_slot *old, struct kvm_memory_slot *old,
const struct kvm_memory_slot *new, const struct kvm_memory_slot *new,
enum kvm_mr_change change) enum kvm_mr_change change)
......
...@@ -703,7 +703,7 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, ...@@ -703,7 +703,7 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
struct kvm_memory_slot *new, struct kvm_memory_slot *new,
enum kvm_mr_change change) enum kvm_mr_change change)
{ {
return kvmppc_core_prepare_memory_region(kvm, mem, old, new, change); return kvmppc_core_prepare_memory_region(kvm, old, new, change);
} }
void kvm_arch_commit_memory_region(struct kvm *kvm, void kvm_arch_commit_memory_region(struct kvm *kvm,
...@@ -712,7 +712,7 @@ void kvm_arch_commit_memory_region(struct kvm *kvm, ...@@ -712,7 +712,7 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
const struct kvm_memory_slot *new, const struct kvm_memory_slot *new,
enum kvm_mr_change change) enum kvm_mr_change change)
{ {
kvmppc_core_commit_memory_region(kvm, mem, old, new, change); kvmppc_core_commit_memory_region(kvm, old, new, change);
} }
void kvm_arch_flush_shadow_memslot(struct kvm *kvm, void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment