1 From 9b42ad76df55bc578ce4845e931d809ad4098b38 Mon Sep 17 00:00:00 2001
2 From: Christian Borntraeger <borntraeger@de.ibm.com>
3 Date: Fri, 24 May 2019 16:06:23 +0200
4 Subject: KVM: s390: fix memory slot handling for KVM_SET_USER_MEMORY_REGION
6 [ Upstream commit 19ec166c3f39fe1d3789888a74cc95544ac266d4 ]
8 kselftests exposed a problem in the s390 handling for memory slots.
9 Right now we only do proper memory slot handling for creation of new
10 memory slots. Neither MOVE, nor DELETION are handled properly. Let us
13 Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
14 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
15 Signed-off-by: Sasha Levin <sashal@kernel.org>
17 arch/s390/kvm/kvm-s390.c | 35 +++++++++++++++++++++--------------
18 1 file changed, 21 insertions(+), 14 deletions(-)
20 diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
21 index c4180ecfbb2a..ee35f1112db9 100644
22 --- a/arch/s390/kvm/kvm-s390.c
23 +++ b/arch/s390/kvm/kvm-s390.c
24 @@ -4413,21 +4413,28 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
25 const struct kvm_memory_slot *new,
26 enum kvm_mr_change change)
30 - /* If the basics of the memslot do not change, we do not want
31 - * to update the gmap. Every update causes several unnecessary
32 - * segment translation exceptions. This is usually handled just
33 - * fine by the normal fault handler + gmap, but it will also
34 - * cause faults on the prefix page of running guest CPUs.
36 - if (old->userspace_addr == mem->userspace_addr &&
37 - old->base_gfn * PAGE_SIZE == mem->guest_phys_addr &&
38 - old->npages * PAGE_SIZE == mem->memory_size)
42 - rc = gmap_map_segment(kvm->arch.gmap, mem->userspace_addr,
43 - mem->guest_phys_addr, mem->memory_size);
46 + rc = gmap_unmap_segment(kvm->arch.gmap, old->base_gfn * PAGE_SIZE,
47 + old->npages * PAGE_SIZE);
50 + rc = gmap_unmap_segment(kvm->arch.gmap, old->base_gfn * PAGE_SIZE,
51 + old->npages * PAGE_SIZE);
56 + rc = gmap_map_segment(kvm->arch.gmap, mem->userspace_addr,
57 + mem->guest_phys_addr, mem->memory_size);
59 + case KVM_MR_FLAGS_ONLY:
62 + WARN(1, "Unknown KVM MR CHANGE: %d\n", change);
65 pr_warn("failed to commit memory region\n");