Skip to content

Commit ecd42dd

Browse files
committed
Merge tag 'kvm-s390-master-6.17-1' of https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux into HEAD
- KVM mm fixes - Postcopy fix
2 parents f6f43a5 + 5f9df94 commit ecd42dd

File tree

3 files changed

+34
-21
lines changed

3 files changed

+34
-21
lines changed

arch/s390/kvm/interrupt.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2778,12 +2778,19 @@ static unsigned long get_ind_bit(__u64 addr, unsigned long bit_nr, bool swap)
27782778

27792779
static struct page *get_map_page(struct kvm *kvm, u64 uaddr)
27802780
{
2781+
struct mm_struct *mm = kvm->mm;
27812782
struct page *page = NULL;
2783+
int locked = 1;
2784+
2785+
if (mmget_not_zero(mm)) {
2786+
mmap_read_lock(mm);
2787+
get_user_pages_remote(mm, uaddr, 1, FOLL_WRITE,
2788+
&page, &locked);
2789+
if (locked)
2790+
mmap_read_unlock(mm);
2791+
mmput(mm);
2792+
}
27822793

2783-
mmap_read_lock(kvm->mm);
2784-
get_user_pages_remote(kvm->mm, uaddr, 1, FOLL_WRITE,
2785-
&page, NULL);
2786-
mmap_read_unlock(kvm->mm);
27872794
return page;
27882795
}
27892796

arch/s390/kvm/kvm-s390.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4864,12 +4864,12 @@ static void kvm_s390_assert_primary_as(struct kvm_vcpu *vcpu)
48644864
* @vcpu: the vCPU whose gmap is to be fixed up
48654865
* @gfn: the guest frame number used for memslots (including fake memslots)
48664866
* @gaddr: the gmap address, does not have to match @gfn for ucontrol gmaps
4867-
* @flags: FOLL_* flags
4867+
* @foll: FOLL_* flags
48684868
*
48694869
* Return: 0 on success, < 0 in case of error.
48704870
* Context: The mm lock must not be held before calling. May sleep.
48714871
*/
4872-
int __kvm_s390_handle_dat_fault(struct kvm_vcpu *vcpu, gfn_t gfn, gpa_t gaddr, unsigned int flags)
4872+
int __kvm_s390_handle_dat_fault(struct kvm_vcpu *vcpu, gfn_t gfn, gpa_t gaddr, unsigned int foll)
48734873
{
48744874
struct kvm_memory_slot *slot;
48754875
unsigned int fault_flags;
@@ -4883,13 +4883,13 @@ int __kvm_s390_handle_dat_fault(struct kvm_vcpu *vcpu, gfn_t gfn, gpa_t gaddr, u
48834883
if (!slot || slot->flags & KVM_MEMSLOT_INVALID)
48844884
return vcpu_post_run_addressing_exception(vcpu);
48854885

4886-
fault_flags = flags & FOLL_WRITE ? FAULT_FLAG_WRITE : 0;
4886+
fault_flags = foll & FOLL_WRITE ? FAULT_FLAG_WRITE : 0;
48874887
if (vcpu->arch.gmap->pfault_enabled)
4888-
flags |= FOLL_NOWAIT;
4888+
foll |= FOLL_NOWAIT;
48894889
vmaddr = __gfn_to_hva_memslot(slot, gfn);
48904890

48914891
try_again:
4892-
pfn = __kvm_faultin_pfn(slot, gfn, flags, &writable, &page);
4892+
pfn = __kvm_faultin_pfn(slot, gfn, foll, &writable, &page);
48934893

48944894
/* Access outside memory, inject addressing exception */
48954895
if (is_noslot_pfn(pfn))
@@ -4905,7 +4905,7 @@ int __kvm_s390_handle_dat_fault(struct kvm_vcpu *vcpu, gfn_t gfn, gpa_t gaddr, u
49054905
return 0;
49064906
vcpu->stat.pfault_sync++;
49074907
/* Could not setup async pfault, try again synchronously */
4908-
flags &= ~FOLL_NOWAIT;
4908+
foll &= ~FOLL_NOWAIT;
49094909
goto try_again;
49104910
}
49114911
/* Any other error */
@@ -4925,7 +4925,7 @@ int __kvm_s390_handle_dat_fault(struct kvm_vcpu *vcpu, gfn_t gfn, gpa_t gaddr, u
49254925
return rc;
49264926
}
49274927

4928-
static int vcpu_dat_fault_handler(struct kvm_vcpu *vcpu, unsigned long gaddr, unsigned int flags)
4928+
static int vcpu_dat_fault_handler(struct kvm_vcpu *vcpu, unsigned long gaddr, unsigned int foll)
49294929
{
49304930
unsigned long gaddr_tmp;
49314931
gfn_t gfn;
@@ -4950,18 +4950,18 @@ static int vcpu_dat_fault_handler(struct kvm_vcpu *vcpu, unsigned long gaddr, un
49504950
}
49514951
gfn = gpa_to_gfn(gaddr_tmp);
49524952
}
4953-
return __kvm_s390_handle_dat_fault(vcpu, gfn, gaddr, flags);
4953+
return __kvm_s390_handle_dat_fault(vcpu, gfn, gaddr, foll);
49544954
}
49554955

49564956
static int vcpu_post_run_handle_fault(struct kvm_vcpu *vcpu)
49574957
{
4958-
unsigned int flags = 0;
4958+
unsigned int foll = 0;
49594959
unsigned long gaddr;
49604960
int rc;
49614961

49624962
gaddr = current->thread.gmap_teid.addr * PAGE_SIZE;
49634963
if (kvm_s390_cur_gmap_fault_is_write())
4964-
flags = FAULT_FLAG_WRITE;
4964+
foll = FOLL_WRITE;
49654965

49664966
switch (current->thread.gmap_int_code & PGM_INT_CODE_MASK) {
49674967
case 0:
@@ -5003,7 +5003,7 @@ static int vcpu_post_run_handle_fault(struct kvm_vcpu *vcpu)
50035003
send_sig(SIGSEGV, current, 0);
50045004
if (rc != -ENXIO)
50055005
break;
5006-
flags = FAULT_FLAG_WRITE;
5006+
foll = FOLL_WRITE;
50075007
fallthrough;
50085008
case PGM_PROTECTION:
50095009
case PGM_SEGMENT_TRANSLATION:
@@ -5013,7 +5013,7 @@ static int vcpu_post_run_handle_fault(struct kvm_vcpu *vcpu)
50135013
case PGM_REGION_SECOND_TRANS:
50145014
case PGM_REGION_THIRD_TRANS:
50155015
kvm_s390_assert_primary_as(vcpu);
5016-
return vcpu_dat_fault_handler(vcpu, gaddr, flags);
5016+
return vcpu_dat_fault_handler(vcpu, gaddr, foll);
50175017
default:
50185018
KVM_BUG(1, vcpu->kvm, "Unexpected program interrupt 0x%x, TEID 0x%016lx",
50195019
current->thread.gmap_int_code, current->thread.gmap_teid.val);

arch/s390/kvm/pv.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,17 @@ int kvm_s390_pv_init_vm(struct kvm *kvm, u16 *rc, u16 *rrc)
624624
int cc, ret;
625625
u16 dummy;
626626

627+
/* Add the notifier only once. No races because we hold kvm->lock */
628+
if (kvm->arch.pv.mmu_notifier.ops != &kvm_s390_pv_mmu_notifier_ops) {
629+
/* The notifier will be unregistered when the VM is destroyed */
630+
kvm->arch.pv.mmu_notifier.ops = &kvm_s390_pv_mmu_notifier_ops;
631+
ret = mmu_notifier_register(&kvm->arch.pv.mmu_notifier, kvm->mm);
632+
if (ret) {
633+
kvm->arch.pv.mmu_notifier.ops = NULL;
634+
return ret;
635+
}
636+
}
637+
627638
ret = kvm_s390_pv_alloc_vm(kvm);
628639
if (ret)
629640
return ret;
@@ -659,11 +670,6 @@ int kvm_s390_pv_init_vm(struct kvm *kvm, u16 *rc, u16 *rrc)
659670
return -EIO;
660671
}
661672
kvm->arch.gmap->guest_handle = uvcb.guest_handle;
662-
/* Add the notifier only once. No races because we hold kvm->lock */
663-
if (kvm->arch.pv.mmu_notifier.ops != &kvm_s390_pv_mmu_notifier_ops) {
664-
kvm->arch.pv.mmu_notifier.ops = &kvm_s390_pv_mmu_notifier_ops;
665-
mmu_notifier_register(&kvm->arch.pv.mmu_notifier, kvm->mm);
666-
}
667673
return 0;
668674
}
669675

0 commit comments

Comments
 (0)