Skip to content

Commit 45921d0

Browse files
author
Claudio Imbrenda
committed
KVM: s390: Fix gmap_link()
The slow path of the fault handler ultimately called gmap_link(), which assumed the fault was a major fault, and blindly called dat_link(). In case of minor faults, things were not always handled properly; in particular the prefix and vsie marker bits were ignored. Move dat_link() into gmap.c, renaming it accordingly. Once moved, the new _gmap_link() function will be able to correctly honour the prefix and vsie markers. This will cause spurious unshadows in some uncommon cases. Fixes: 94fd9b1 ("KVM: s390: KVM page table management functions: lifecycle management") Fixes: a2c17f9 ("KVM: s390: New gmap code") Reviewed-by: Steffen Eiden <seiden@linux.ibm.com> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
1 parent 6f93d1e commit 45921d0

3 files changed

Lines changed: 52 additions & 54 deletions

File tree

arch/s390/kvm/dat.c

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -997,54 +997,6 @@ bool dat_test_age_gfn(union asce asce, gfn_t start, gfn_t end)
997997
return _dat_walk_gfn_range(start, end, asce, &test_age_ops, 0, NULL) > 0;
998998
}
999999

1000-
int dat_link(struct kvm_s390_mmu_cache *mc, union asce asce, int level,
1001-
bool uses_skeys, struct guest_fault *f)
1002-
{
1003-
union crste oldval, newval;
1004-
union pte newpte, oldpte;
1005-
union pgste pgste;
1006-
int rc = 0;
1007-
1008-
rc = dat_entry_walk(mc, f->gfn, asce, DAT_WALK_ALLOC_CONTINUE, level, &f->crstep, &f->ptep);
1009-
if (rc == -EINVAL || rc == -ENOMEM)
1010-
return rc;
1011-
if (rc)
1012-
return -EAGAIN;
1013-
1014-
if (WARN_ON_ONCE(unlikely(get_level(f->crstep, f->ptep) > level)))
1015-
return -EINVAL;
1016-
1017-
if (f->ptep) {
1018-
pgste = pgste_get_lock(f->ptep);
1019-
oldpte = *f->ptep;
1020-
newpte = _pte(f->pfn, f->writable, f->write_attempt | oldpte.s.d, !f->page);
1021-
newpte.s.sd = oldpte.s.sd;
1022-
oldpte.s.sd = 0;
1023-
if (oldpte.val == _PTE_EMPTY.val || oldpte.h.pfra == f->pfn) {
1024-
pgste = __dat_ptep_xchg(f->ptep, pgste, newpte, f->gfn, asce, uses_skeys);
1025-
if (f->callback)
1026-
f->callback(f);
1027-
} else {
1028-
rc = -EAGAIN;
1029-
}
1030-
pgste_set_unlock(f->ptep, pgste);
1031-
} else {
1032-
oldval = READ_ONCE(*f->crstep);
1033-
newval = _crste_fc1(f->pfn, oldval.h.tt, f->writable,
1034-
f->write_attempt | oldval.s.fc1.d);
1035-
newval.s.fc1.sd = oldval.s.fc1.sd;
1036-
if (oldval.val != _CRSTE_EMPTY(oldval.h.tt).val &&
1037-
crste_origin_large(oldval) != crste_origin_large(newval))
1038-
return -EAGAIN;
1039-
if (!dat_crstep_xchg_atomic(f->crstep, oldval, newval, f->gfn, asce))
1040-
return -EAGAIN;
1041-
if (f->callback)
1042-
f->callback(f);
1043-
}
1044-
1045-
return rc;
1046-
}
1047-
10481000
static long dat_set_pn_crste(union crste *crstep, gfn_t gfn, gfn_t next, struct dat_walk *walk)
10491001
{
10501002
union crste newcrste, oldcrste;

arch/s390/kvm/dat.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,6 @@ int dat_set_slot(struct kvm_s390_mmu_cache *mc, union asce asce, gfn_t start, gf
540540
u16 type, u16 param);
541541
int dat_set_prefix_notif_bit(union asce asce, gfn_t gfn);
542542
bool dat_test_age_gfn(union asce asce, gfn_t start, gfn_t end);
543-
int dat_link(struct kvm_s390_mmu_cache *mc, union asce asce, int level,
544-
bool uses_skeys, struct guest_fault *f);
545543

546544
int dat_perform_essa(union asce asce, gfn_t gfn, int orc, union essa_state *state, bool *dirty);
547545
long dat_reset_cmma(union asce asce, gfn_t start_gfn);

arch/s390/kvm/gmap.c

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -631,10 +631,60 @@ static inline bool gmap_1m_allowed(struct gmap *gmap, gfn_t gfn)
631631
return test_bit(GMAP_FLAG_ALLOW_HPAGE_1M, &gmap->flags);
632632
}
633633

634+
static int _gmap_link(struct kvm_s390_mmu_cache *mc, struct gmap *gmap, int level,
635+
struct guest_fault *f)
636+
{
637+
union crste oldval, newval;
638+
union pte newpte, oldpte;
639+
union pgste pgste;
640+
int rc = 0;
641+
642+
rc = dat_entry_walk(mc, f->gfn, gmap->asce, DAT_WALK_ALLOC_CONTINUE, level,
643+
&f->crstep, &f->ptep);
644+
if (rc == -ENOMEM)
645+
return rc;
646+
if (KVM_BUG_ON(rc == -EINVAL, gmap->kvm))
647+
return rc;
648+
if (rc)
649+
return -EAGAIN;
650+
if (KVM_BUG_ON(get_level(f->crstep, f->ptep) > level, gmap->kvm))
651+
return -EINVAL;
652+
653+
if (f->ptep) {
654+
pgste = pgste_get_lock(f->ptep);
655+
oldpte = *f->ptep;
656+
newpte = _pte(f->pfn, f->writable, f->write_attempt | oldpte.s.d, !f->page);
657+
newpte.s.sd = oldpte.s.sd;
658+
oldpte.s.sd = 0;
659+
if (oldpte.val == _PTE_EMPTY.val || oldpte.h.pfra == f->pfn) {
660+
pgste = gmap_ptep_xchg(gmap, f->ptep, newpte, pgste, f->gfn);
661+
if (f->callback)
662+
f->callback(f);
663+
} else {
664+
rc = -EAGAIN;
665+
}
666+
pgste_set_unlock(f->ptep, pgste);
667+
} else {
668+
do {
669+
oldval = READ_ONCE(*f->crstep);
670+
newval = _crste_fc1(f->pfn, oldval.h.tt, f->writable,
671+
f->write_attempt | oldval.s.fc1.d);
672+
newval.s.fc1.sd = oldval.s.fc1.sd;
673+
if (oldval.val != _CRSTE_EMPTY(oldval.h.tt).val &&
674+
crste_origin_large(oldval) != crste_origin_large(newval))
675+
return -EAGAIN;
676+
} while (!gmap_crstep_xchg_atomic(gmap, f->crstep, oldval, newval, f->gfn));
677+
if (f->callback)
678+
f->callback(f);
679+
}
680+
681+
return rc;
682+
}
683+
634684
int gmap_link(struct kvm_s390_mmu_cache *mc, struct gmap *gmap, struct guest_fault *f)
635685
{
636686
unsigned int order;
637-
int rc, level;
687+
int level;
638688

639689
lockdep_assert_held(&gmap->kvm->mmu_lock);
640690

@@ -646,9 +696,7 @@ int gmap_link(struct kvm_s390_mmu_cache *mc, struct gmap *gmap, struct guest_fau
646696
else if (order >= get_order(_SEGMENT_SIZE) && gmap_1m_allowed(gmap, f->gfn))
647697
level = TABLE_TYPE_SEGMENT;
648698
}
649-
rc = dat_link(mc, gmap->asce, level, uses_skeys(gmap), f);
650-
KVM_BUG_ON(rc == -EINVAL, gmap->kvm);
651-
return rc;
699+
return _gmap_link(mc, gmap, level, f);
652700
}
653701

654702
static int gmap_ucas_map_one(struct kvm_s390_mmu_cache *mc, struct gmap *gmap,

0 commit comments

Comments
 (0)